Forum Discussion

Eric_Weiss_2486's avatar
Eric_Weiss_2486
Icon for Nimbostratus rankNimbostratus
Feb 14, 2016

Can you wildcard cookie name with HTTP::cookie?

Can the cookie name in HTTP::cookie be wildcarded, like so?

 

when HTTP_REQUEST {

 

Check for SSO Cookie if { ( ! [HTTP::cookie exists "*.test"] ) } { reject } }

 

Thanks, Eric

 

6 Replies

  • zeiss_63263's avatar
    zeiss_63263
    Historic F5 Account

    Hi Eric,

     

    Matching a regexp on HTTP::cookie should be a trivial exercise. There's a nice example here where a Class of regex strings was created and the iRule runs a foreach loop to parse each entry:

     

    https://devcentral.f5.com/codeshare?sid=479

     

    There's nothing intrinsically special about HTTP::cookie. You can match and manipulate the content of this field in much the same way you can match any TCL var. If you want to just match anything with 'test' don't forget the "contains" criterion.

     

    Check out this page https://devcentral.f5.com/articles/irules-101-10-regular-expressions and heed the examples and warnings.

     

  • Hi Eric,

    you can't use wildcards in combination with the

    [HTTP::cookie exists]
    command. But you may use either one of these coding techniques...

    foreach cookie_name [HTTP::cookie names] {
        if { $cookie_name contains ".test" } then {
            reject
            break
        }
    }
    

    ... or even using the

    [cookie names]
    list as a whole...

    if { [HTTP::cookie names] contains ".test" } then {
        reject
    }
    

    Cheers, Kai

  • Thank you very much, zeiss and Kai. Would this be the correct reverse on the above then?

     

    foreach cookie_name [HTTP::cookie names] { if { $cookie_name ! contains ".test" } then { reject break } }

     

    ... or even using the [cookie names] list as a whole...

     

    if { ! [HTTP::cookie names] contains ".test" } then { reject }

     

    • Kai_Wilke's avatar
      Kai_Wilke
      Icon for MVP rankMVP
      I'd prefer "if { not ( [HTTP::cookie names] contains ".test" ) } then { reject }" Cheers, Kai