Forum Discussion

Dana_19378's avatar
Dana_19378
Icon for Nimbostratus rankNimbostratus
Nov 14, 2013

HTTP Events in iRules

I have seen some iRules that appear to violate the understnding I have of the HTTP_REQUEST and HTTP_RESPONSE events.

Assuming an iRule has both events like below, my assumption up until now is that each time the rule executes, no values are saved from the previous execution, and both events cannot coexist during the same execution since the current state is either REQUEST or RESPONSE. Based on this, I assume the if statement in the below 'when HTTP_RESPONSE' would never be true in the below example, and { set a "bar" } would never happen. Am I mistaken?

rule fubar {
when HTTP_REQUEST {
   set a "foo" 
   }
when HTTP_RESPONSE { 
   if ($a equals "foo") {
      set a "bar" 
      } 
   } 
}

Thanks

2 Replies

  • Variables are available and exist on a connection or session related basis (session in this case). So in your example, yes, I expect the if to return true. If you don't want this behaviour, use the unset command.

     

  • If I may add, local variables will exist within the span of a single TCP session. An HTTP request and its corresponding response should always, unless programmatically designed otherwise, exist within a single TCP session. It's even conceivable, albeit not guaranteed, that multiple request/response pairs could exist within a single TCP session, allowing the local variables to span these pairs. Therefore you can usually assume that any variable set in an HTTP request event will be available in the subsequent response event - but you should ALWAYS check for their existent first, as a matter of best practice.