Extracting a specific Set-Cookie header in HTTP_RESPONSE

(This is a followup to this post: Click here)

How can I extract the value of a specific Set-Cookie header?

I’m trying to use a cookie for universal persistence, but I could not find a way to find the value of more than one Set-Cookie header in the server response.

It doesn’t appear that the [HTTP::cookie names] works against Set-Cookie headers in the response, despite this post (Click here) regarding universal persistence which seems to indicate it will list the cookies being set in the server response.

I get a blank list when I do the same thing, which actually makes sense, since they are not cookies yet, just Set-Cookie headers.

So it seemed like I need to grab the Set-Cookie header instead, but if there are multipe cookies being set, I can’t seem to extract anything but the first one with [HTTP::header Set-Cookie].

I was thinking maybe something like this:

while {[HTTP::header Set-Cookie]}{if...}

, but was not sure if that would iterate them all, or loop endlessly, or break prematurely if Set-Cookie headers are not contiguous or…?

thoughts appreciated…

/deb

Thanks, Colin.

I am seeing the data I expect in the server response, and it works fine if the cookie I want is in the first Set-Cookie header.

But the server can insert multiple Set-Cookie headers to set multiple cookies, instead of setting them all in the same header instance (usually seen when the extra parameters are different - path, expiry, domain commonly vary).

How can I extract the one cookie value I need if it’s not set in the first Set-Cookie header?

thanks!

/deb

any update on this, Deb/Colin?

A little bit late but, this code works for me :wink:

when HTTP_RESPONSE {
   First of all, we check if a Set-cookie header exists
  if { [HTTP::header count "Set-cookie" ] > 0 } {
    set all_set_cookies [HTTP::header "Set-cookie"
    foreach one_set_cookie $all_set_cookies {
       Whe are looking for a cookie named "myCookie"
      if { $one_set_cookie contains "myCookie" } {
         Whatever you want to do with "myCookie" ;)
      }
    }
  }
}

Regards!