Forum Discussion
commsmonkey_172
Nimbostratus
Oct 01, 2011Hi 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"
}
}