Forum Discussion
F5 iRule for Header insert
Hello,
I create that iRule below, but my header value for the header x-id is still empty, what could be wrong ?
when HTTP_REQUEST {
foreach header_name [HTTP::header names] {
if {([HTTP::header value $header_name] eq "x-id")} {
set VALUE [HTTP::header "XXX#YYYY" ]
HTTP::header insert "x-id" $VALUE
}
}
}
kind regards
eLeCtRoN
- CypherCirrus
it seems you want to replace the header value with something else? What do you want to accomplish exactly?
You can try this.
if { [HTTP::header exists x-id] } {
set VALUE [HTTP::header "XXX#YYYY"]
#log command to determine if VALUE is set correctly
log local0. "x-idlog var VALUE=$VALUE"
# header x-d allready exists -> remove it first.
HTTP::header remove x-id
# add header x-id with variable VALUE
HTTP::header insert x-id $VALUE
}The problem might be the var VALUE is not set correctly, and is thus empty.
- eLeCtRoNCirrus
Hello Cypher,
our header x-id is empty per default and the WAF doesen't like that and blocks our request, so I want to set a value
for the header x-id, now I set your iRule active and the header is still empty, in the system log I got just the messages
HTTP :header insert x-id $VALUE syslog-ng log local0. \"x-idlog var VALUE=$VALUE\" - CypherCirrus
i would troubleshoot 'bottom-up' and use lowercase for variables (not sure if that has an impact, but it is a good practice).
i don't know what XXX#YYYY is, but it needs to exists as a header, or whatever you use instead of XXX#YYYY. so lets see if it exists first in the logs.
when HTTP_REQUEST {
foreach header_name [HTTP::header names] {
log local0. "$header_name"
}
if { [HTTP::header exists x-id] } {
set value [HTTP::header "XXX#YYYY"]
#log command to determine if VALUE is set correctly
log local0. "x-idlog var value=${value}"
# header x-id allready exists -> remove it first.
HTTP::header remove x-id
# add header x-id with variable value
HTTP::header insert x-id $value
}
}check system > logs > local traffic for errors and logs.
- JRahmAdmin
Hi eLeCtRoN do you also have a header named XXX#YYYY? If not, then that's going to be an empty value anyway. If you are trying to:
- Assure the x-id header exists
- Assure that the x-id header has a value
Then, something like this should work for you:
when HTTP_REQUEST priority 500 { if { [HTTP::header exists x-id] && ([HTTP::header x-id] == "") } { HTTP::header replace x-id "some value here" } else { HTTP::header insert x-id "some value here" } }
if you don't need the header to be there then you can eliminate the else statement altogether.
- eLeCtRoNCirrus
Hi Jason,
just short tell you what I have, I have form the application the header x-id with no value inside (empty), so my WAF policy don't like that and block the request, what I now want to do is just to set a value inside the header x-id. Thanks for your response
- JRahmAdmin
then that should work for you as is, or without the else block.
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