Contribute Open Script

[BRCD_OS_103] Client-IP Insertion

by Derek_Kang on ‎01-06-2012 02:21 PM (288 Views)

Area:

Content manipulation

Traffic:

HTTP

Description:

            This script checks the incoming client’s source-ip and inserts it in the request going out to the server. The header used is “X-Forwarded-For”, but it can be changed to any other text. All requests are forwarded to server-group 30.

Performance Estimate

            TBD

Required Backend configuration

            No special configuration is required

Events and API Used

Events

API

HTTP_REQUEST

OS_IP::src

OS_HTTP_REQUEST::header($name,$value)

OS_SLB::forward("group")

Script source code

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

# Purpose: Get the Client IP address from IP header and Insert it in the

#          HTTP Request using header “X-Forwarded-For”.

#     

use OS_SLB;

use OS_IP;

use OS_HTTP_REQUEST;

sub HTTP_REQUEST {

       my $client_ip = OS_IP::src;

       print "Client IP Address - $client_ip\n";

       OS_HTTP_REQUEST::header("X-Forwarded-For", "$client_ip");

       OS_SLB::forward("30");

}