Contribute Open Script

[BRCD_OS_104] Request Header Insertion

by Derek_Kang on ‎01-06-2012 02:19 PM (254 Views)

Area:

Content Manipulation

Traffic:

HTTP

Description:

            This script insert a custom headers in all HTTP Requests going through the ADX.

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::header

OS_SLB::forward("group")

Script source code

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

# Purpose: Insert Header into Request and forward to a server group

# Inserting the Header - "User-Defined: Custom Header 101"

use OS_SLB;

use OS_HTTP_REQUEST;

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

#

# HTTP REQUEST EVENT

#

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

sub HTTP_REQUEST {

       print "\n\nreceived Client Request\n\n";

       OS_HTTP_REQUEST::header("User-Defined", "Custom Header 101");

       OS_SLB::forward("10");

}

sub SERVER_SELECTION_FAILURE {

       print "\n\n*** Selected group Servers not available. Send Error Code 500 to Client***\n\n";

       my $req_vers = OS_HTTP_REQUEST::version;

       my $err_code = "HTTP/$req_vers 500 Server Error\r\nConnection: Close\r\nContent-Length: 0\r\n\r\n";

       OS_SLB::reply_error($err_code);

}