Alex_Ma_58639
Dec 03, 2008Nimbostratus
add HTTP Header
How to write a iRule to check if the incoming HTTP header is "abc123" then add a header "efg123" in front of "abc123"?
You can use HTTP::header (Click here) to check if a header exists and to insert a new header or modify a new header.
Do you want to check if the header name is abc123 or the header value is abc123? Does the order of the HTTP headers matter? By default if you insert a new header it will be inserted after the existing headers. If you need the new header inserted before the existing one, you could insert the new one, save the value of the old one, remove the old one and insert a new instance of the old header.
Aaron
Could you show me how to use the HTTP:Header insert, I need to add a new header before the old header, and check if the incoming header is "abc" then add a new header "efg" before the "abc".
Thanks
GET / HTTP/1.1
Host: somehost.example.com
ABC: abcs_value
And you want to check if there is an ABC header and if so insert a new header named EFG like this:
GET / HTTP/1.1
Host: somehost.example.com
EFG: efg_value
ABC: abc_value
If so, this should work:
when HTTP_REQUEST {
Check if ABC header exists
if {[HTTP::header exists "ABC"]}{
Save the value of ABC
set abc_value [HTTP::header value "ABC"]
Remove the ABC header
HTTP::header remove "ABC"
Insert the EFG header
HTTP::header insert "EFG" value "efg_value"
Insert the ABC header again so it's after the EFG header
HTTP::header insert "ABC" value $abc_value
}
}
Note that I haven't tested it, but it looks about right. If you run into any issues, try adding some logging to the iRule.
Thanks,
Aaron