Contribute Open Script

[BRCD_OS_120] Redirect Mobile Traffic

by Yasir_Liaqatullah on ‎01-20-2012 03:28 PM (606 Views)

Area

Content inspection

Traffic

HTTP

Description

            This script analyzes the incoming request and looks for the header User-Agent. If this header is found and has a value of “mobile”, the request is redirected. If not, the request is forwarded to a server. The example script assumes there will be only one header “User-Agent” in the request.

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

Script source code

# Purpose: Redirect incoming Requests if they have the header "User-Agent: mobile"

use OS_SLB;

use OS_HTTP_REQUEST;

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

#

# HTTP REQUEST EVENTS

#

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

sub HTTP_REQUEST {

       # Get the value of header User-Agent, if found in request

       my $my_user_agent = "";

       $my_user_agent = OS_HTTP_REQUEST::header("User-Agent");

       #print "The value of User-Agent header in Request is - $my_user_agent\n";

       if ($my_user_agent =~ m/mobile/) {

              #print "Request coming from a Mobile.. Redirecting..\n";

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

       } else {

              #print "Request not coming from Mobile. Forwarding the request to the server\n";

              OS_SLB::forward("30");

       }

       }