Forum Discussion
lbong_53781
Nimbostratus
Oct 01, 2009HTTP::COOKIE not working as expected
I am running LTM 10.0.1
I have the following iRule and run into some issues when there are multiple cookie variable in the header. The Rule seems to only look at the last "Cookie:" variable in the header. If "My_Cookie" is the last cookie statement in the header, it will work. But if its not, it will not see "My_Cookie".
when HTTP_REQUEST {
if {[HTTP::cookie exists "My_Cookie"]} {
if {[HTTP::cookie "My_Cookie"] equals "1"} {
use pool My_Pool
} else {
use pool My_Pool_2
}
} else {
use pool Other_Pool
}
}
I tried to send the following to the F5 to test the rule.
do echo && echo -n "$number ";GET -Ssed -H 'User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2 (.NET CLR 3.5.30729)' -H 'Cookie: TID=5555%2D51020900262051001033859%2D0' -H 'Cookie: My_Cookie=1' -H 'Cookie: CHOSEN_BANNER=1' -H 'Host: mysite.com' http://mysite.com/?test=$number
3 Replies
- hoolio
Cirrostratus
Can you add logging to the test rule and post the results when it fails? In a quick test, this functionality seemed to work okay:when HTTP_REQUEST { Insert some test headers HTTP::header insert header1 value1 HTTP::header insert header2 value2 Test the header exists command for both headers if {[HTTP::header exists header1]}{ log local0. "header1 exists" } else { log local0. "header1 does not exist" } if {[HTTP::header exists header2]}{ log local0. "header2 exists" } else { log local0. "header2 does not exist" } Loop through each header by name and log the name and value foreach header [HTTP::header names] { log local0. "$header: [HTTP::header values $header]" } }
: header1 exists
: header2 exists
: User-Agent: {curl/7.16.3 (i686-pc-cygwin) libcurl/7.16.3 OpenSSL/0.9.8k zlib/1.2.3 libssh2/0.15-CVS}
: Host: piggybank
: Accept: */*
: header1: value1
: header2: value2
Aaron - lbong_53781
Nimbostratus
Thanks for looking into this.
The issue is not with the header. Its with the evaluation of [HTTP::COOKIE].
When the last Cookie in the header is "My_Cookie" it works fine. When the last Cookie is not, the [HTTP::COOKIE] functions seem to not able to find "My_Cooke".
Below is my test script.
This will fail,
do echo && echo -n "$number ";GET -Ssed -H 'User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2 (.NET CLR 3.5.30729)' -H 'Cookie: TID=5555%2D51020900262051001033859%2D0' -H 'Cookie: My_Cookie=1' -H 'Cookie: CHOSEN_BANNER=1' -H 'Host: mysite.com' http://mysite.com/?test=$number
This will work correctly,
do echo && echo -n "$number ";GET -Ssed -H 'User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2 (.NET CLR 3.5.30729)' -H 'Cookie: TID=5555%2D51020900262051001033859%2D0' -H 'Cookie: CHOSEN_BANNER=1' -H 'Cookie: My_Cookie=1' -H 'Host: mysite.com' http://mysite.com/?test=$number
Thanks - hoolio
Cirrostratus
Sorry... I misread your post. On 10.0.1, the cookie value seems to work:when HTTP_REQUEST { HTTP::cookie insert name cookie1 value value1 HTTP::cookie insert name cookie2 value value2 if {[HTTP::cookie exists cookie1]}{ log local0. "cookie1 exists" } else { log local0. "cookie1 does not exist" } if {[HTTP::cookie exists cookie2]}{ log local0. "cookie2 exists" } else { log local0. "cookie2 does not exist" } log local0. "Cookie names ([HTTP::cookie names])" foreach cookie [HTTP::cookie names] { log local0. "\[HTTP::cookie value $cookie\]: [HTTP::cookie value $cookie]" } }
: cookie1 exists
: cookie2 exists
: Cookie names (cookie1 cookie2)
: [HTTP::cookie value cookie1]: value1
: [HTTP::cookie value cookie2]: value2
Can you add logging to your iRule and post the results from HTTP::cookie exists "cookie_name" and HTTP::cookie value "cookie_name"?
Aaron
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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