Contribute Open Script

[BRCD_OS_115] Response Header Insertion

by Yasir_Liaqatullah on ‎01-20-2012 02:44 PM (578 Views)

Area

Header Insertion

Traffic

HTTP

Description

            This script analyzes the response from server and inserts a new header before forwarding the response to client.

Performance Estimate

            TBD

Required Backend configuration

            No special configuration is required

Events and API Used

Events

API

HTTP_REQUEST

OS_HTTP_RESPONSE::header

OS_HTTP_RESPONSE:Smiley Tongueush_header

Script source code

#Purpose: Header Insertion in Response

use OS_SLB;

use OS_HTTP_RESPONSE;

sub HTTP_RESPONSE () {

   #print "HTTP Response event is triggered\n";

   # Define new header with name followed by value

   my @new_header = ("X-Robots-Tag", "NOINDEX");

   # Check if the header exists in the response

   # If there is no such header, insert new one

   # If there is a header with same name, insert another one

   my $header_exists = OS_HTTP_RESPONSE::header("$new_header");

   if (!$header_exists) {

              #print "No $new_header in the response. Insert one..\n";

              OS_HTTP_RESPONSE::header("$new_header", "$new_header");

       } else {

              #print "$new_header is found in the response. Push another one..\n";

              OS_HTTP_RESPONSE:Smiley Tongueush_header("$new_header", "$new_header");

       }

}