Forum Discussion
iRule to inspect case-insensitive string
I am trying to compose an irule which examines a 'POST' in http header, doesn't care about case as it may be capitals or not, and processes as normal if that value is present. If that value is NOT present - reject the inbound connection.
Here is where I'm at:
when HTTP_REQEUST {
set keyvalue 0
if { [HTTP::method] equals "POST"} {
set http_headers [HTTP::header names]
foreach header $http_headers {
if {tolower $header equals "somevalue"} {
set keyvalue if we find the header
keyvalue == 1
}
}
if {$keyvalue ne 1} {
TCP::close
}
}
}
^^This is not taking into the LTM v9.4.5, so I assume I have some formatting error or other issue.^^
-------------------------------------------------
Another potential one is:
when HTTP_REQUEST {
if {[HTTP::method] equals "POST"} {
set http_headers [HTTP::header names]
[$http_headers "somevalue"] if {$index == -1} { TCP::close } } }
^^this doesn't evaluate case insensitivity though^^
I'm hoping there is an easy way to accomplish what I'm after.
Thank you.
- Chris_MillerAltostratusYou need "string tolower" and not just "tolower."
- hooleylistCirrostratusThe header name matching in [HTTP::header value NAME] isn't case sensitive. So you could just look for the header name without a loop or setting the name to lower case.
- TaSM1_90432NimbostratusThank you Hoolio. That is good to know as the requirement is to have this be non case sensitive.
- hooleylistCirrostratusThis should work to check close TCP connections when a POST without a required header name is parsed:
when HTTP_REQUEST { Check for POST requests if {[HTTP::method] eq "POST"}{ if { not ([HTTP::header exists "my_required_header_name"])}{ TCP::close } } }
- TaSM1_90432NimbostratusThank you Aaron. Your expertise is much appreciated.
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