Contribute Open Script

[BRCD_OS_108] Response Header Manipulation

by Yasir_Liaqatullah on ‎01-20-2012 02:15 PM (230 Views)

Area

Content Rewrite

Traffic

HTTP

Description

            This script analyzes the server-responses and if it finds multiple “Set-Cookie” headers, it retrieves the values from each header and consolidate them in one.

Performance Impact

           

            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_SLB::forward

HTTP_RESPONSE

OS_HTTP_RESPONSE::headers

OS_HTTP_RESPONSE:Smiley Tongueush_header

OS_HTTP_RESPONSE::remove_headers

Script source code

#

# Analyze server response, if multiple Set-Cookie headers are found, retrieve cookies from each one and consolidate them in one Set-Cookie header.
use OS_SLB;
use OS_HTTP_REQUEST;
use OS_HTTP_RESPONSE;
#############################################
#
# HTTP RESPONSE EVENTS
#
#############################################
sub HTTP_REQUEST {
OS_SLB::forward(10);
}
sub HTTP_RESPONSE {
     my @set_cookie_headers = OS_HTTP_RESPONSE::headers("Set-Cookie");
     if ( defined $set_cookie_headers && $#set_cookie_headers > 0 ) {
         my $mySetCookie = $set_cookie_headers;
         for ($counter = 1; $counter <= $#set_cookie_headers; $counter++) {
            $mySetCookie = $mySetCookie.";".$set_cookie_headers;
         }
         OS_HTTP_RESPONSE::remove_headers("Set-Cookie");
         OS_HTTP_RESPONSE:Smiley Tongueush_header("Set-Cookie","$mySetCookie");
     }
}