Forum Discussion

Rusty_Hale_8009's avatar
Rusty_Hale_8009
Icon for Nimbostratus rankNimbostratus
Apr 26, 2005

Grab value out of cookie and store it in a header variable

I have information that resides in a cookie:

 

 

JetNetUser=XXXXXXXX

 

 

I want to grab this information out of the cookie and insert it into the http header and store the value (XXXXXXXX) into a variable called

 

auth-user

 

 

What would the syntax be to do this?

 

 

Thanks in advance for your help.

 

 

2 Replies

  • unRuleY_95363's avatar
    unRuleY_95363
    Historic F5 Account
     
     when HTTP_REQUEST { 
        set auth_user [HTTP::cookie JetNetUser] 
        HTTP::header insert JetNetUser $auth_user 
     } 
     

    It might be wise to avoid the hyphen character in a variable name as it makes referencing it a bit more cumbersome (you need to always enclose it in braces, eg ${auth-user}). I used the underscore character instead in the above example.

  • I understood the question to mean that JetNetUser was part of the cookie. If that's the case, try

    when HTTP_REQUEST {  
        set auth_user [findstr [HTTP::cookie ] "JetNetUser" 11 "&" ]  
        HTTP::header insert  $auth_user  
      }

    I'm assuming here the terminator of your string will be &, so you'll need to change this if it's not.