Contribute Open Script

[BRCD_OS_102] Host Header Switching

by Derek_Kang on ‎01-06-2012 01:42 PM (229 Views)

Area:

Content Manipulation

Traffic:

HTTP

Description:

                This script analyzes incoming requests and depending on the host-header, sends a redirect. The script uses the redirect API in multiple ways to introduce the additional parameters which can be used while sending a redirect message.

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

OS_SLB::redirect

Script source code

# Purpose: Check Host Header and based on that respond with redirect messages

# Host with

#                              www.host1.com - default redirect

#                              www.host2.com - redirect domain

#                              www.host3.com - redirect domain, status-code

#                              www.host4.com - redirect domain, status-code, url

#                              www.host5.com - redirect domain, status-code, url, port

#                              If no match, send reset to Client

use OS_SLB;

use OS_HTTP_REQUEST;

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

#

# HTTP REQUEST EVENTS

#

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

sub HTTP_REQUEST {

          

                # Get the URL from the request

                my $client_host = OS_HTTP_REQUEST::host;

                print "\n\nClient Request has this HOST Header - $client_host\n\n";

                # Group selection based on the HOST in the request

                if ($client_host =~ m/www.host1.com$/) {

                                print "Matched www.host1.com";

                                OS_SLB::redirect;

                } elsif ($client_host =~ m/www.host2.com$/) {

                                print "Matched www.host2.com";

                                OS_SLB::redirect("domain" => "www.newhost2.com");

                } elsif ($client_host =~ m/www.host3.com$/) {

                                print "Matched www.host3.com";

                                OS_SLB::redirect("domain" => "www.newhost3.com", "status-code" => "302");

                } elsif ($client_host =~ m/www.host4.com$/) {

                                print "Matched www.host4.com";

                                OS_SLB::redirect("domain" => "www.newhost4.com", "status-code" => "302", "url" => "/newpage4.html");

                } elsif ($client_host =~ m/www.host5.com$/) {

                                print "Matched www.host5.com";

                                OS_SLB::redirect("domain" => "www.newhost5.com", "status-code" => "302", "url" => "/newpage5.html", "port" => "8980");

                } else {

                                print "Did not match predefined Host. Send reset to client";

                                OS_SLB::reset_client();

                }

}