Forum Discussion
Karthik_124840
Mar 18, 2014Nimbostratus
How to check if response contains a specific string using IRules
Hi All,
I have a requirement to change a cookie attribute if the http response has a specific string in it. Can anyone please let me know how it can acheived ?
cdougall_14195
Mar 18, 2014Cirrus
So a few more details of what you're trying to do would help, but you can start here and see where you get to. This is some code that modifies a jsession cookie and persists on it. If you can give some more info, might be able to get a bit closer to what you're trying to do.
when HTTP_REQUEST {
Check if cookie has a value
if {[HTTP::cookie "JSESSIONID"] ne ""}{
Parse the three ! delineated fields from the cookie
if {[scan [HTTP::cookie JSESSIONID] {%[^:]:%[^:]:%[^:]} session holder pri_server_hash] == 3}{
HTTP::cookie value "JSESSIONID" "$session:$holder"
Persist off of the primary server token if it is present, not a null value and has a current persistence record
if {$pri_server_hash ne ""}{
persist uie $pri_server_hash
}
}
}
}
when HTTP_RESPONSE {
Check if cookie has a value
if {[HTTP::cookie "JSESSIONID"] ne ""}{
Parse the second field of the cookie value.
The current server always sets its hash as the primary server hash in the second field of the cookie.
set jsession [HTTP::cookie "JSESSIONID"]
append jsession ":[IP::remote_addr]"
HTTP::cookie value "JSESSIONID" $jsession
persist add uie [IP::remote_addr]
}
}
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