Contribute Open Script

[BRCD_OS_109] Cookie Insertion and Persistence

by Yasir_Liaqatullah on ‎01-25-2012 05:30 PM (1,261 Views)

Scripting                       Cookie Persistence

Area

Content inspection

Traffic

HTTP

Description

            This script can be used to enable cookie persistence on the ADX. When the ADX receives a new request, it will select a server with the server ID specified by the cookie value and forward the request. The ADX will insert a custom cookie with the server ID value in the response sent to the client. The client will use the inserted cookie in all subsequent requests. Whenever such a request arrives, the ADX will analyze the data and if it finds the cookie, select the server it initially selected. If there is no cookie, a new cookie will be inserted in the response by the ADX.

Performance Estimate

           

            Contact us for our detailed reporting

               or

            Report your own performance estimate

Required Backend configuration

            No special configuration is required except basic L7 SLB on the ADX such as server group-id and server-id.

Events and API Used

Events

API

HTTP_REQUEST

OS_HTTP_REQUEST::cookie

OS_SLB:Smiley Tongueersist

Script source code

#

use OS_SLB;

use OS_HTTP_REQUEST;

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

#

# HTTP REQUEST EVENTS

#

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

sub HTTP_REQUEST {

 

       # Get the Cookie from the request

       my $hreq_cookie = OS_HTTP_REQUEST::cookie("ServerID");

 

        if (defined $hreq_cookie) {

            # forward to server with group id or server id identified by cookie

            OS_SLB::forward($hreq_cookie);

        } else {

            #forward to server with group-id 10, insert set-cookie in response to client

            OS_SLB::forward("10");

            OS_HTTP_REQUEST::cookie_persist("name"=>"ServerID","domain" => "www.brocade.com","path" => "/home", "age" => 1024);

        }

}

Comments
by aaron.hackney
on ‎10-18-2012 08:29 AM

Hello,

For OS_HTTP_REQUEST::cookie_persist, the API Guide shows a different set of parameters for than what is on your example:

API Guide:

OS_HTTP_REQUEST::cookie_persist("name"=>$cookie_name,

"domain"=>$domain, "port"=>$port, "age"=>$age)

Above Example:

OS_HTTP_REQUEST::cookie_persist("name"=>"ServerID","domain" => "www.brocade.com","path" => "/home", "age" => 1024);

So the discrepency is path vs port. Can you comment on which is correct?

When using path, I see the following my in URL DEBUG:

SRW: create rewrite unknown for "ServerID........%args...........$name............foobar.com.....$domain.........%args...........$path...........$domain.........$age............$log............$data...ode.....$url....y.......$port.." "/"

    insertSmiley Frustratedet-Cookie: ServerID=X   ; domain=.foobar.com; path=/\r\n(len:0)
    Set to insert HTTP header (Set-Cookie: ServerID=1034; domain=.foobar.com; path=/

)!