Forum Discussion
lipos_54863
Nimbostratus
Aug 05, 2009persisting on a cookie
Hi,
I'm wondering is there a way to create a persistence based on a cookie when checking only first three letters of the cookie name?
Here's my example:
when HTTP_RESPONSE {
if { [HTTP::cookie exists "1234567890"] } {
persist add uie [HTTP::cookie "1234567890"]
}
}
when HTTP_REQUEST {
if { [HTTP::cookie exists "1234567890"] } {
persist uie [HTTP::cookie "1234567890"]
}
}
Part 1234 never changes, but 567890 will.
Any suggestions?
- hoolio
Cirrostratus
If you want to parse part of the cookie value, you can use 'string range' (Click here) to get it. It would be good to make sure there is a value before trying to persist on it. - lipos_54863
Nimbostratus
I need to persist on a cookie but its name changes every session. - hoolio
Cirrostratus
Sorry, for the cookie name, you could loop through the cookies by name:foreach a_cookie [HTTP::cookie names] { if {$a_cookie starts_with "1234"}{ Found a cookie that starts with 1234, so do something } }
- lipos_54863
Nimbostratus
Thank you!when HTTP_RESPONSE { foreach a_cookie [HTTP::cookie names] { if {$a_cookie starts_with "1234"}{ persist add uie [HTTP::cookie "$a_cookie"] log local0.debug "Cookie persist - client IP: [IP::client_addr], Cookie: $a_cookie, Server IP: [IP::server_addr]" } else { persist source_addr 255.255.255.255 3600 log local0.debug "Source persist - client IP: [IP::client_addr] , Server IP: [IP::server_addr]" } } } when HTTP_REQUEST { foreach a_cookie [HTTP::cookie names] { if {$a_cookie starts_with "1234"}{ persist uie [HTTP::cookie "a_cookie"] log local0.debug "Client IP: [IP::client_addr], Cookie value: $a_cookie" } } }
- lipos_54863
Nimbostratus
I think I finally got it.}timing on HTTP responds catches the first responds from the node to back to the client. It checking all cookies in the header and grabs all starting with 1234. After it adds the cookie value to the persistance table and log values to syslog. Else persist the client for 60 minutes based on source IP with /32 mask and log values to syslog. when HTTP_RESPONSE { foreach a_cookie [HTTP::cookie names] { if {$a_cookie starts_with "1234"}{ persist add uie [HTTP::cookie "$a_cookie"] log local0.debug "Cookie persist - client IP: [IP::client_addr], Cookie: $a_cookie, Server IP: [IP::server_addr]" } else { persist source_addr 255.255.255.255 3600 log local0.debug "Source persist - client IP: [IP::client_addr] , Server IP: [IP::server_addr], lookup [persist lookup uie [IP::client_addr]]" } } } HTTP request catches the first responds from the node to back to the client. It checking all cookies in the header and grabs all starting with 1234. After it persist on the cookie value in the persistance table. Aslo, log values to syslog when HTTP_REQUEST { foreach a_cookie [HTTP::cookie names] { if {$a_cookie starts_with "1234"}{ persist uie [HTTP::cookie "a_cookie"] log local0.debug "Client IP: [IP::client_addr], Cookie value: $a_cookie" } else { persist uie [IP::client_addr] log local0.debug "Source IP Persistence used - Client IP: [IP::client_addr], Persistance entries used persist uie [persist lookup uie [IP::client_addr]]" } } }
- wayney_128269
Nimbostratus
How is "persist add uie" different from "persist uie"? - The_Bhattman
Nimbostratus
There is article about posted here
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