Forum Discussion

ST_Wong's avatar
ST_Wong
Icon for Cirrus rankCirrus
Aug 18, 2015

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 /
      }
    }

8 Replies

  • Hi, It's been a long time, but, have you fixed this issue? [ ]
  • Hi, not yet... as I switched to handle some other 'high priority' tasks :(
  • David_Larsen_23's avatar
    David_Larsen_23
    Historic F5 Account
    The 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"
  • 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.

     

  • Thanks 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.
  • 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 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 ) { }