Forum Discussion
Pierce_Fortin
Nimbostratus
Dec 12, 2017iRule replace substring in cookie name
Hi,
I need to write an iRule which will rewrite part of the cookie name and the cookie path. For example:
Set-Cookie: ASP.NET_SessionId=f3izvd1kvrlsfy0wc2ui1t5k;Path=/ needs to become:
Set-Cookie: SpecialName-SessionID=f3izvd1kvrlsfy0wc2ui1t5k;Path=/foo-bar/
when HTTP_RESPONSE {
set cookies [HTTP::cookie names]
foreach cookie $cookies {
set cookie_value [HTTP::cookie $cookie]
set cookie_path [string map -nocase {"/" "/FOO-BAR/"}
[HTTP::cookie path $cookie]]
set cookie_name [string map -nocase {"ASP.NET_SessionID" "Special-Name-"}
[HTTP::cookie path $cookie]]
HTTP::cookie remove $cookie
HTTP::cookie insert name $cookie value $cookie_value path $cookie_path
}
}
The first part (rewriting the path) works but rewriting the cookie name fails, I think it's because its expecting to match on the full string but I need to match on a substring.
- Pierce_Fortin
Nimbostratus
I wrongly understood how cookies were formatted. This works for me:
when HTTP_RESPONSE { set cookies [HTTP::cookie names] foreach cookie $cookies { set cookie_value [HTTP::cookie $cookie] set cookie_path [string map -nocase {"/" "/FOO-BAR/"} [HTTP::cookie path $cookie]] HTTP::cookie remove $cookie HTTP::cookie insert name Special-Name value $cookie_value path $cookie_path } }
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