Forum Discussion

Kevin_Jones_505's avatar
Kevin_Jones_505
Historic F5 Account
Feb 08, 2006

HTTP_REQUEST and POSTs

I'd like an iRule that acts based on values in a POST. Can I use the HTTP_REQUEST event, or would I need to use a CLIENT_ACCEPTED and combine it with an HTTP::method?

 

 

thanks.
  • 
    when HTTP_REQUEST {
      if { [HTTP::method] equals "POST" }
        
      }
    }

    THere are several examples in this forum that utilize HTTP::method, these should get you started.
  • That will tell you whether it is a POST request or not. If you want to act on the data within the POST, you will have to issue a collect and work with the HTTP::payload value in the HTTP_REQUEST_DATA event.

    Something like this should get you started:

    when HTTP_REQUEST {
      if { [HTTP::method] equals "POST" } {
        if { [HTTP::header exists "Content-Length"] } {
          set content_length [HTTP::header "Content-Length"]
        } else {
          set content_length 4294967295
        }
        if { $content_length > 0 } {
           this will trigger the HTTP_REQUEST_DATA event when all the
           POST data has arrived.
          HTTP::collect $content_length
        }
      }
    }
    when HTTP_REQUEST_DATA {
       check the HTTP::payload for it's contents.
      if { [HTTP::payload] contains "somevalue" } {
         do something here...
      }
    }