Forum Discussion
- Chris_MillerAltostratusThe wiki is your best friend...for this rule, we'll use subsets of the "HTTP::" command
when HTTP_REQUEST { if { [string tolower [HTTP::uri]] contains "/folder" } { HTTP::cookie insert "name" value "value" } }
- Andrea_ArquintNimbostratus@ Chris
- Chris_MillerAltostratusPosted By bigbrother on 10/20/2010 06:47 AM
Would it be like "www.sample.com/test" ?
Try "HTTP::cookie insert name "NewCookie" value "test" path /"
The cookie belongs to whatever domain you're accessing. In my example, it would be for "www.sample.com"
- Chris_MillerAltostratusI just had a total brain-fart. We need to do cookie insert in the response event.
when HTTP_REQUEST { if { [string tolower [HTTP::uri]] contains "/folder" } { set cinsert 1 } else { set cinsert 0 }} when HTTP_RESPONSE { if { $cinsert eq 1 } { HTTP::cookie insert "name" value "value" path / }}
- Andrea_ArquintNimbostratusI do the same you explained...
when HTTP_REQUEST {
set uagent [string tolower [HTTP::header User-Agent]]switch -glob [HTTP::host] {www.testdom.com {if { [HTTP::uri] starts_with "/test" } {HTTP::cookie insert name "ClassicView" value "mobile" path /} else {log local0. "no cookie set"}}unset uagent}
But the cookie is not set ???
- Andrea_ArquintNimbostratusHi Chris
okay I got it...
I have to do the following:
1. when HTTP_REQUEST
- matches any request conditions
If the request condition matches
2. when HTTP_RESPONSE
- set cookie
ahh and you check with the variable cinsert that the RESPONSE works even if the condtition matches right?
Do you have an example somewhere?
Kind regards
andy
- Chris_MillerAltostratusPosted By bigbrother on 10/20/2010 07:20 AM I do the same you explained...
when HTTP_REQUEST {
set uagent [string tolower [HTTP::header User-Agent]]switch -glob [HTTP::host] {if { [HTTP::uri] starts_with "/test" } {HTTP::cookie insert name "ClassicView" value "mobile" path /} else {log local0. "no cookie set"}}unset uagent}
But the cookie is not set ???
The example above your post should work. I can modify yours as well.
when HTTP_REQUEST {
set uagent [string tolower [HTTP::header User-Agent]]
switch -glob [HTTP::host] {
if { [HTTP::uri] starts_with "/test" } {
set cinsert 1
} else {
set cinsert 0
log local0. "no cookie set"
}
}
unset uagent
}
when HTTP_RESPONSE {
if { $cinsert eq 1 } {
HTTP::cookie insert name "ClassicView" value "mobile" path / }}
May I ask how you're using the uagent variable here? Is it for something separate from the cookie logic?
- Andrea_ArquintNimbostratusHi Chris
Yes it is for something separated. Because we want also integrate in this iRule mobile device detection.
Ok I will try your steps...
- Andrea_ArquintNimbostratusThe cookie is set but I get following ltm error:
- Andrea_ArquintNimbostratusahh okay I see...