Forum Discussion
Greg_34053
Aug 02, 2011Nimbostratus
detecting redirection
Hi,
I have an irule that sends the clients IP address to the back end web server via a cookie. The cookie is not sent to the user. The rule worked fine unless an earlier rule had called HTT...
Greg_34053
Aug 02, 2011Nimbostratus
I tested the boundary conditions and found that when you delete the last cookie that a Cookie header still exists so the code has been altered to put correct syntax for the first cookie in the header (no preceding "; ")
Also tested when no cookies presented and it added the Cookie header correctly and my diagnostic irule that followed and the web server in the pool both showed the cookie correctly.
All that is left is "How can I tell if a redirect is happening due to an earlier irule?" Then I could probably get rid of the catch.
when HTTP_REQUEST {
set my_cookie_name "CIP"
set client_ip_addr [IP::client_addr]
Check if a cookie header exists
if { [HTTP::header exists Cookie] } then {
while { [HTTP::cookie exists $my_cookie_name] } {
HTTP::cookie remove $my_cookie_name
}
if { [HTTP::cookie count] > 0 } then {
set new_Cookie_header "[HTTP::header value Cookie]; $my_cookie_name=$client_ip_addr"
} else {
set new_Cookie_header "$my_cookie_name=$client_ip_addr"
}
catch {HTTP::header replace Cookie $new_Cookie_header} dont_care
}
else {
set new_Cookie_header "$my_cookie_name=$client_ip_addr"
catch {HTTP::header insert Cookie $new_Cookie_header} dont_care
}
}
Author: Greg Palmer 2011/08/02
Adds client IP to the cookie header if it can - catches error and continues otherwise
NB Putting this rule first in the list will allow it to allows add the cookie and hence no error to catch
Looks for Cookie header
if found removes all cookies whose name is CIP and modifies the cookie header to contain the required Cookie
if not found it adds a cookie header with the cookie
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