Forum Discussion
Cannot insert cookie
Hi all,
I tried to do URI based pool selection on first request. Then sequence requests will be directed to the same pool even the URI doesn't match. I use simple codes like following, however, the cookie can't be inserted. We're using outdated 9.4.8... Would anyone please help?
Thanks and rgds
/ST Wong
when HTTP_REQUEST {
set myCheck 0
if {[HTTP::cookie exists "X-DWSpool"]} {
pool test1-pool
} else {
switch -glob [string tolower [HTTP::uri]] {
"/test1/*" {
pool test1-pool
set myCheck 1
}
"/test2/*" {
pool test2-pool
}
default {
pool default-pool
}
}
}
}
when HTTP_RESPONSE {
if ($myCheck) {
HTTP::cookie insert name "X-DWSpool" value "foo" path /
}
}
- cjuniorNacreousHi, It's been a long time, but, have you fixed this issue? [ ]
- ST_WongCirrusHi, not yet... as I switched to handle some other 'high priority' tasks :(
- David_Larsen_23Historic F5 AccountThe cookie insert you are doing is an HTTP Header cookie correct? You might have better luck with HTTP::header instead: HTTP::header insert X-DWSpool "foo"
- Kevin_StewartEmployee
Your code actually looks correct. Can you verify that you're not getting a cookie when attempting to access a /test1/ URI the first time? Try this:
curl -v http://x.x.x.x/test1/
Or if this is an SSL VIP:
curl -vk https://x.x.x.x/test1/
The -v will show your request and the corresponding response. You're looking for Set-Cookie header in that response.
- ST_WongCirrusThanks for all your help. Tried to test with original code, or using HTTP::header instead but both failed. Yes, I'm using CURL to test. Thanks.
- Kevin_StewartEmployee
Tried to test with original code, or using HTTP::header instead but both failed.
Yes, but just to clarify, do you see the Set-Cookie header in the cURL response? If not, try taking out the "if ($myCheck)" conditional just to see if cookie insertion works at all.
- Stanislas_Piro2Cumulonimbus
Hi,
can you replace :
if ($myCheck) {
by :
if {$myCheck} {
- Kevin_StewartEmployee
Stanislas is absolutely correct. I didn't catch that at first. You might be confusing TCL syntax with Perl or JavaScript. An if condition is wrapped in curly braces, not parenthesis.
Correct:
if { something } { }
Incorrect:
if ( something ) { }
Recent Discussions
Related Content
* 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