Forum Discussion

efreeman_26356's avatar
efreeman_26356
Icon for Nimbostratus rankNimbostratus
Mar 30, 2012

Difficult cookie rewrite problem

 

 

All:

 

I need to create an irule that does the following:

 

 

1. If the client is an https connection, Insert header “MIG_Protocol” with value “https”

 

2. If client request “User-Agent” string contains "AppleWebKit" and contains "Safari" and does not contain "Chrome"

 

AND

 

If cookie value “mdata” with third number between [1322629200, 1329523199]

 

Action: Clean existing cookie, set cookie value to new value.” new=1|23|4567”

 

Here is an example of a cookie I am trying to modify:

 

 

Cookie: id=985208336314226; path=/; expires=Sun, 07-Apr-13 18:43:49 GMT; path=/; domain=. example.com, mdata=1|985208336314226|1331232229; path=/; expires=Sun, 07-Apr-13 18:43:49 GMT; path=/; domain=. example.com, OAX=z9pHGU9Y/eUAAxue; path=/; expires=Sun, 07-Apr-13 18:43:49 GMT; path=/; domain=. example.com

 

Is there a way to specify the third number in the mdata field?

 

Here is what I have so far (sytax is correct but hasn't been tested):

 

when HTTP_REQUEST {

 

if { [HTTP::uri] contains "secure"} {

 

HTTP::header insert "MIG_Protocol" "https"

 

}

 

 

set httpuri [string tolower [HTTP::uri]]

 

set useragent [string map {" " "_"} [string tolower [HTTP::header user-agent]]]

 

if {

 

((!($useragent contains "applewebkit"))) && (([$useragent contains "safari"]))

 

&& (([$useragent not "chrome"]))

 

&& (([$mdata >= 1322629200]))

 

&& (([$mdata <= 1329523199]))

 

}{

 

HTTP::cookie discard

 

HTTP::cookie "new=1|23|4567"

 

} }

 

 

 

Thanks,

 

 

 

  • 
    if { [HTTP::cookie exists "mdata"] } {
       set mdata  [getfield [HTTP::cookie value "mdata"] "|" 3]
    }