Forum Discussion
iRule removes second value of header cache-control
Hi all,
I'm trying to remove all values after the comma of cache-control header
cache-control: no-cache, max-age=0
For instance here I want to keep
cache-control: no-cache,
it is not necessarily no-cache,
I want to keep the first value and remove the rest.
Via an iRule I should be able to do that but as I am quite inexperienced in this field, I need your help.
This is what I already did:
when HTTP_RESPONSE {
if {[string tolower [HTTP::header]] matches_regex cache-control\s*:\s*(public|private|no-cache|no-store|no-transform|max-age\s*[=]{1}\s*[0-9]{1,8}|max-stale\s*[=]{1}\s*[0-9]{1,8}|min-fresh\s*[=]{1}\s*[0-9]{1,8}|min-vers\s*[=]{1}\s*[0-9]{1,8}|must-revalidate|proxy-revalidate|only-if-cached)\s*[\,]{1}
}
}
I don't know if I'm on the right way, so do not hesitate to propose a solution.
Regards,
Tarik
- dragonflymr
Cirrostratus
Hi,
Maybe try getfield for that:
if { [HTTP::header "Cache-Control" exists] } { set new_hdr set new [getfield [HTTP::header "Cache-Control"] "," 1] HTTP::header replace "Cache-Control" $new_header }
Not the best code but should work. Probably it would be good to check if there are no multiple instances of Cache-Control header because above code will replace value only in last instance of header.
pro
- Morten_Marstran
Nimbostratus
Regarding Piotr's comment on checking for multiple instances of "Cache-Control", you could use HTTP::remove and then HTTP::insert, like this:
if { [HTTP::header "Cache-Control" exists] } { set new_header [getfield [HTTP::header "Cache-Control"] "," 1] HTTP::header remove "Cache-Control" HTTP::header insert "Cache-Control" $new_header }
Recent Discussions
Related Content
* 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