For more details, please see ourCookie Policy.

Learn OpenScript

HTTP Request/Response Correlation with Connection hash

by Derek_Kang on ‎01-09-2012 04:56 PM (902 Views)

One of the ADX Perl extensions provides connection scoping for script data. Scripts can use these special hashes to manage per connection data. For example, multiple Request-Response flows are possible within a single TCP connection.  Scripts can hang application specific data in the connection flow hash that can be referenced across Request and Response event handlers. Two types of connection hashes are available:

  • Client side connection – OS_SLB::client_connection, the unique client connection index
  • Server side connection – OS_SLB::server_connection, the unique server connection index

# Use an HTTP Request handler to retrieve the top level connection hash
# and store HTTP request data.
    My %ua_hash;
    $client_conn = OS_SLB::client_connection;
    # Hang current request method and URI starting at index 0
    %ua_hash{$client_conn} = HTTP::Request::method;

# Retrieve connection specific data in an HTTP response handler.
    $client_conn = OS_SLB::client_connection;
    # Retrieve method and uri.
    given (%ua_hash{$client_conn})  {
        when “Internet Explorer” { handle_IE_response; }
        when “Mozilla”   { handle_Mozilla_response; }
        default          { handle_gen_browser_response(); }

The client and server hash references provide client and server side data scoping. When used with generic layer 4 payload/layer 7 content handlers, these hashes allow for very flexible server selection policies.

All script data associated with connection hashing has the same lifetime as the connection itself. The extension backend manages the memory needed for hashing.