beautypg.com

Os_slb:: reply($data), Example, Context – Brocade Virtual ADX OpenScript API Guide (Supporting ADX v03.1.00) User Manual

Page 111: Usage

background image

Brocade Virtual ADX OpenScript API Guide

99

53-1003243-01

Methods

7

Example

OS_SLB:: reply($data)

Causes the system send an error response to a client instead of forwarding a request to the server.
The error response can be specified in $data or the following default message will be sent: “HTTP/
1.1 403 Forbidden\r\nServer: HTTP Proxy/1.0\r\nConnection: Close\r\nContent-Length:
0\r\n\r\n"“

Context

This function can be called from HTTP request event.

Usage

Can be used to send an error page instead of load balancing traffic.

use OS_SLB;

use OS_HTTP_REQUEST;

use OS_HTTP_RESPONSE;

sub HTTP_REQUEST {

# Get the Cookie from the request

my $mycookie = OS_HTTP_REQUEST::cookie("ServerID");

#print "\n my cookie is: $mycookie\n";

if (defined $mycookie) {

$serverName = OS_SLB::persist_lookup("passive-persist", "$mycookie");

#print "\n\n\n &&& my server is: $serverName\n";

}

if (defined $serverName ) {

# forward to server based on passive cookie persistence

OS_SLB::persist("passive-persist","$mycookie");

} else {

OS_SLB::forward(10);

}

}

sub HTTP_RESPONSE {

$mySetCookie = OS_HTTP_RESPONSE::header("Set-Cookie");

#print "\n my set cookie is: $mySetCookie\n";

if ( $mySetCookie =~ m/.*ServerID=(\d+).*/ ) {

$cookie = $1;

#print "\n my cookie is: $cookie\n";

OS_SLB::passive_persist("add","$cookie");

}

}