Forum Discussion
iRule for missing or blank headers (user-agent and accept)
Hi all, I'm working on another iRule creation. I need to create a rule that will detect if the request headers for user-agent and/or accept is blank/missing. I also need to be able to exclude uri extensions with rss and smil. Below is the iRule I tried to create based on the requirements. Can I get some help with reviewing the rule and letting me know where I've gone wrong please?
when HTTP_REQUEST {
if {not ([HTTP::uri] ends_with "rss") and not ([HTTP::uri] ends_with "smil")}
{
log local0. "URI extension is not rss or smil."
}
elseif { [HTTP::header "User-Agent"] eq "false" }
{
log local0. "User-Agent header is missing."
}
elseif { [HTTP::header "Accept"] eq "false" }
{
log local0. "Accept header is missing."
}
elseif { [HTTP::header "User-Agent"] contains "^$" }
{
log local0. "User-Agent header is blank."
}
elseif { [HTTP::header "Accept"] contains "^$" }
{
log local0. "Accept header is blank."
}
}
3 Replies
- Richard__HarlanHistoric F5 Account
If you want to check if a header exists you can use the following if {[HTTP::header exists User-Agent ]}{
You are checking is the value of User-Agent is False not that it does not exist
- Patti_G_72768
Nimbostratus
Ok. Thank you verymuch!!!
- What_Lies_Bene1
Cirrostratus
It's slightly less specific but this should work (note the HTTP::header command will return null if the header doesn't exist or if the header's value is null);
if { [HTTP::uri] ends_with "rss" or [HTTP::uri] ends_with "smil" } { log local0. "URI extension is rss or smil." Optionally drop the traffic reject Stop executing the irule return } elseif { [HTTP::header "User-Agent"] eq "" } { log local0. "User-Agent header is missing or blank." } elseif { [HTTP::header "Accept"] eq "" } { log local0. "Accept header is missing or blank." }
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