Forum Discussion
jaskel_106221
Nimbostratus
Aug 27, 2007Header insertion (newbie alert)
Hey there,
So, I'm really new to iRules, and I question about a HTTP::header insert
Basically, I am looking to 'replace' the value of a custom(?) header if it exists in the current connection, or insert the header. Here is what I have with some comments:
when HTTP_REQUEST {
Check to see if the header already exists
if { [ string tolower HTTP::header] starts_with "client-"} {
If it does, remove the current header element
HTTP::header remove Client-IP
The insert our own assuring that only one element exists in the
header
HTTP::header insert Client-IP:[IP::remote_addr]
}
else {
If it doesn't already exist, insert it.
HTTP::header insert Client-IP:[IP::remote_addr]
}
}
I created a test virtual server as well to just insert the header no matter what with this code:
when HTTP_REQUEST {
Insert Client-IP:[IP::remote_addr] into
the header for each http request
HTTP::header insert Client-IP:[IP::remote_addr]
}
But, sadly, it appears that neither of these two options are actually inserting a header with:
Client-IP: ip.address.here.
into my HTTP request.
I'm sorry for the lame newbie post....but thanks for looking!
-James
- jaskel_106221
Nimbostratus
Ok, ok....this always happens to me. The minute I post a question, I figure out what I was doing wrong. So, this is what I ended up with: - Kirk_Bauer_1018
Nimbostratus
I'm not clear on what the "HTTP::header" command returns with no arguments? The complete header string? In that case this would only work if client-ip was the first header, correct? - hoolio
Cirrostratus
Otherwise, you can use '[HTTP::header replace "Client-IP" [IP::client_addr]' (Click here), to replace the header with the new value if the header is set already or insert if it's not present already. If you wanted to be doubly sure that no header exists already, you could use this to remove all instances and then insert a new header:when HTTP_REQUEST { while {[HTTP::header exists "Client-IP"]} { HTTP::header remove "Client-IP" } HTTP::header insert "Client-IP" [IP::client_addr] }
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