Forum Discussion
commsmonkey_172
Sep 30, 2011Nimbostratus
Store variable from STREAM::expression and use in HTTP_RESPONSE context
Hi F5ers, I've been looking for a way to store the stream matched hostname in a HREF from a HTML stream. As I rewrite the content from internal domain to external domain using...
commsmonkey_172
Oct 01, 2011Nimbostratus
Hi Aaron,
I thought that was logical too and I've tried that without success prior to posting. It appears the variable set in the STREAM_MATCHED event is reported as out of scope or not known to the HTTP_RESPONSE event, similarly HTTP cookie creation and insertion is out of scope in the STREAM_MATCHED event.
Here's the code with logging enabled for logic debugging:
when STREAM_MATCHED {
set myVar [string tolower [getfield [STREAM::match] "." 1]]
log local0.emerg " myVar variable is $ myVar"
}
when HTTP_REQUEST {
Disable the stream filter for all requests via VS
STREAM::disable
}
when HTTP_RESPONSE {
Disable the stream filter by default
STREAM::disable
Enable the stream filter for text responses only
if {[HTTP::header value Content-Type] contains "text"}{
STREAM::expression {@string@replacementstring@}
Enable the stream filter for this response only
log local0.emerg "Passed stream expression"
STREAM::enable
log local0.emerg "variable $myVar is set now"
}
if {$myVar contains "string"}{
Set Cookie value value to 'string' found by the Stream filter
log local0.emerg "Setting new persist Cookie"
HTTP::cookie insert name "myCookie" value $myVar path "/"
log local0.emerg "Cookie Set and Inserted"
}
}
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects