Forum Discussion
Pierre_G__71801
Aug 08, 2011Nimbostratus
[ProxyPass_v10.3] Bypass Cookie rewriting
Hi,
I'm using ProxyPass to redirects some URIs to a different pool but the Cookies get rewritten from ".domain.com" to "host.domain.com" according to the user request who browses to host.dom...
Mark_Paglieran1
Aug 08, 2011Nimbostratus
Would this work?
Rewrite any domains/paths in Set-Cookie headers
if {[HTTP::header exists "Set-Cookie"]}{
array set cookielist { }
A response may have multiple Set-Cookie headers, loop through them
foreach cookievalue [HTTP::header values "Set-Cookie"] {
set cookiename [getfield $cookievalue "=" 1]
set newcookievalue ""
New check for XYZCOOKIE
if {$cookiename eq "XYZCOOKIE"} {
if {$::ProxyPassDebug > 1} {
log local0. "Skipping XYZ cookie $cookiename"
}
skip to the next iteration of this loop
continue
} end XYZ check
Each cookie starts with name=value and then has more name/value pairs
foreach element [split $cookievalue ";"] {
set element [string trim $element]
if {$element contains "="} {
set elementname [getfield $element "=" 1]
set elementvalue [getfield $element "=" 2]
if {$elementname eq "domain"} {
Rewrite domain of cookie, if necessary.
if {$elementvalue eq $host_serverside} {
if {$::ProxyPassDebug > 1} {
log local0. "Modifying cookie $cookiename domain from $elementvalue to $host_clientside"
}
set elementvalue $host_clientside
}
}
if {$elementname eq "path"} {
Rewrite path of cookie, if necessary.
if {$elementvalue starts_with $path_serverside} {
if {$::ProxyPassDebug > 1} {
log local0. "Modifying cookie $cookiename path from $elementvalue to $path_clientside[substr $elementvalue [string length $path_serverside]]"
}
set elementvalue $path_clientside[substr $elementvalue [string length $path_serverside]]
}
}
append newcookievalue "$elementname=$elementvalue; "
} else {
append newcookievalue "$element; "
}
}
Store new cookie value for later re-insertion. The cookie value
string will end with an extra "; " so strip that off here.
set cookielist($cookiename) [string range $newcookievalue 0 [expr {[string length $newcookievalue] - 3}]]
}
Remove all Set-Cookie headers and re-add them (modified or not)
HTTP::header remove "Set-Cookie"
foreach cookiename [array names cookielist] {
HTTP::header insert "Set-Cookie" $cookielist($cookiename)
if {$::ProxyPassDebug > 1} {
log local0. "Inserting cookie: $cookielist($cookiename)"
}
}
}
}
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects