Forum Discussion

TaSM1_90432's avatar
TaSM1_90432
Icon for Nimbostratus rankNimbostratus
Jan 28, 2011

iRule to inspect case-insensitive string

Hello all:

 

 

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.

 

 

  • You need "string tolower" and not just "tolower."

     

     

    To make sure I understand what you're trying to do:

     

     

    1. Only examine POSTs.

     

    2. Reject POST unless a certain header exists.

     

     

    Are you looking for a certain header name, or any header that has a certain value? The rules above loop through every single header so will be inefficient if you're just looking for a specific one.
  • The 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.

     

     

    Aaron
  • Thank you Hoolio. That is good to know as the requirement is to have this be non case sensitive.

     

     

    If I am understanding then, this irule should meet the requirements then:

     

     

    when HTTP_REQUEST {

     

    if {[HTTP::method] equals "POST"} {

     

    set http_headers [HTTP::header names]

     

    [$http_headers "specific_value_name"] if {$index == -1} { TCP::close } } }
  • This 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
          }
       }
    }
    

    Aaron