Contribute Open Script

[BRCD_OS_110] URL or Cookie Persistence

by Yasir_Liaqatullah on ‎01-20-2012 02:28 PM (372 Views)

Area

Content inspection

Traffic

HTTP

Description

            This script analyzes the incoming request and looks for a cookie, JSessionID. If the cookie is found, the value is extracted and hashed, and a server is selected based on this hash. If the cookie is not found, the URL is inspected to see if there is a JSessionID string. If found, the numeric string following it is extracted and hashed to select a server.

Performance Estimate

           

            Contact us for our detailed reporting

               or

            Report your own performance estimate

Required Backend configuration

            No special configuration is required

Events and API Used

Events

API

HTTP_REQUEST

OS_HTTP_REQUEST::cookie

OS_HTTP_REQUEST::url

OS_SLB::persist

Script source code

#

#

#

use OS_SLB;

use OS_HTTP_REQUEST;

#############################################

#

# HTTP REQUEST EVENTS

#

#############################################

sub HTTP_REQUEST {

        my $JSESSIONID = 0;

       # Extract the URL from the request

       my $client_url = OS_HTTP_REQUEST::url;

 

       # Extract the Cookie from the request

       $JSESSIONID = OS_HTTP_REQUEST::cookie("JSESSIONID");

       # Check if either the cookie exist as a header or if it is

        # embedded within the URL. If found, persist on the cookie value

        # to select a server.

        if ( $JSESSIONID != 0 ) {

            OS_SLB::persist("hash-to-bucket", "$JSESSIONID");

        } elsif ( $client_url =~ /^(.*)JSESSIONID=(\d+)(.*)$/ ) {

            OS_SLB::persist("hash-to-bucket", $2);

        } else {

          # forward to request to server-group 10

          OS_SLB::forward(10);

        }

}