Forum Discussion

JSpartan0901_95's avatar
JSpartan0901_95
Icon for Nimbostratus rankNimbostratus
Mar 08, 2012

Ability to correlate HTTP response to a HTTP request in iRules

Hi,

 

 

We have a requirement to perform certain operations on HTTP response only for specific HTTP requests. Is there any way I can correlate a response to a request in iRules?

 

 

Thanks!

 

-J

 

3 Replies

  • Hi J,

    You can set a variable in HTTP_REQUEST and check for it in HTTP_RESPONSE event:

    
    when HTTP_REQUEST {
    
    if {$some_check==1}{
    set check_response 1
    } else {
    set check_response 0
    }
    }
    when HTTP_RESPONSE {
    if {$check_response==1}{
     do something
    }
    }
    

    Aaron
  • Thanks, Aaron. I am novice in iRules.

     

     

    Is this thread safe? Does it work for concurrent requests from multiple clients?
  • Yes, local variables are tied to a connection. Global variables (those set using 'set ::my_var value' in any non-RULE_INIT event or those set as 'set my_var value' or 'set ::my_var value' in RULE_INIT) are available across all connections. SMP summarized this nicely in this post. It's relevant for v10 and v11.

     

     

    v10 - local vs. global vars

     

    https://devcentral.f5.com/Community/GroupDetails/tabid/1082223/asg/50/aft/1172260/showtab/groupforums/Default.aspx1172986

     

     

    Aaron