Forum Discussion

Mahesh_56902's avatar
Mahesh_56902
Icon for Nimbostratus rankNimbostratus
Mar 30, 2007

Context between HTTP request and respose

Can I have context between HTTP request and response? In other words, if I set a variable in an iRule script in request event, can I access it in response event for that connection?

3 Replies

  • Sure can. Variables without a namespace are automatically assigned to the current connection. So, as long as it's during the same connection, you can set variables in one event, and retrieve them from another.

    when HTTP_REQUEST {
      set orig_uri [HTTP::uri]
    }
    when HTTP_RESPONSE {
      log local0. "Original URI: $orig_uri"
    }

    -Joe
  • Thanks Joe.

     

     

    Extending this concept, can I have a variable (read/write) that spans connections?

     

    eg: some counter that keeps track of a specific kind of traffic (based on some custom criteria)
  • Sure can, but keep in mind that there are no build-in safeguards for overwriting the values across connections. Counters and totals are fine as they aren't connection specific. You could do something like this:

    when RULE_INIT {
      set ::total_requests 0
    }
    when HTTP_REQUEST {
      incr ::total_requests 1
    }

    A better approach though would be to use the Statistics Profile to build your own name/value pairs. This data is peristent and is accessible from within iRules with the STATS::get and STATS::set commands as well as through iControl. Take a look at the Docs section for my latest tech tip on custome reporting with iRules.

    -Joe