Forum Discussion
http::header value question
I'm trying to write an irule where based on the value of a custom http header it redirects to different servers. Its a little clunky, but when I figure where I'm going I put the values in datagroup with a matchclass statement. The header abc is a string with bunch of numbers, and the irule looks at the last number and redirects based on that. Anyway, this is what I have, and unfortunately, after trying a bunch of things, I still haven't been able to save it without syntax errors.
when HTTP_REQUEST {
if { ([HTTP::header value abc] ends_with "1") OR ([HTTP::header value abc] ends_with "2") OR ([HTTP::header value abc] ends_with "3") OR ([HTTP::header value abc] ends_with "4") OR ([HTTP::header value abc] ends_with "5")} {
node 1.1.1.1 443
} elseif { ([HTTP::header value abc] ends_with "6") OR ([HTTP::header value abc] ends_with "7") OR ([HTTP::header value abc] ends_with "8") OR ([HTTP::header value abc] ends_with "9") OR ([HTTP::header value abc] ends_with "0")} {
node 2.2.2.2 443
} else {
default_pool
}
}
4 Replies
Hi Atoth,
I don't think that a data-group is the right choice for this task. The possible values are not that much and are also rather static.
But you may try the syntax below. It uses the
command with[switch]-glob
and*[01234]
patterns to route your request based on the last digit of the given header value...*[56789]when HTTP_REQUEST { switch -glob -- [HTTP::header value abc] { "*[01234]" { node 1.1.1.1 443 } "*[56789]" { node 2.2.2.2 443 } default { pool default_pool } } }Cheers, Kai
- atoth
Cirrus
That worked! Thanks!
One thing I wondered. What does the "--" after switch -glob do?
- janholtz_40468
Nimbostratus
Kai is CORRECTLY terminating the options for switch, something which I should be doing but often forget...
 
https://devcentral.f5.com/s/articles/irules-101-04-switch
 
"--"
 
Marks the end of options. The argument following this one will be treated as string even if it starts with a -
 
You're welcome! 😉
And yes, the
will close the--
section to make the syntax more robust.switch -optionCheers, Kai
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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
