selecting reproxy pool to use based on request_uri

Robby Dermody robbyd at u20.org
Fri Oct 5 22:47:43 UTC 2007


Hey guys,

I have a perlbal plugin that hooks into 'start_proxy_request' in order to
slap on some extra http headers for incoming requests. I'd like to enhance
this plugin to reproxy an incoming request to one of two pools depending on
the request made. This is because I have a server A handling requests to
/foo and /bar (e.g. a pool of one server), and a server B, C and D handling
requests to everything else (e.g. a different pool of 3 servers). I'd like
to just use port 80 and forward to one or the other as needed. Thus I would
avoid having to use both 80 and some other, non-standard port and having
people behind restrictive firewalls not be able to access the service
possibly.

The skeleton of new code would probably look like what I have below, but I
am totally lost with how to have perbal use a different backend than the one
specified in the active service.is this possible? Can I do it in
start_proxy_request, or does it have to be another hook? Any code or
pointers that could be provided would help out (I'm not a perl developer,
obviously :).

myplugin.pm:
[.]

$svc->register_hook('CastdotGlue', 'start_proxy_request', sub {
my Perlbal::ClientProxy $cliproxy = shift;
my Perlbal::HTTPHeaders $hds = $cliproxy->{req_headers};
       my Perlbal::Service $svc = $cliproxy->{service};
return 0 unless defined $hds && defined $svc;
return 0 unless $hds->request_uri;
if($hds->request_uri =~ m/^\/foo.*/i || $hds->request_uri =~ m/^\/bar.*/i)
{
	//reproxy to an entry in the first pool
}
else
{
	//reproxy to an entry in the second pool
}

[.] 
    # existing functionality that slaps on the headers is here, etc.
}

[.]




More information about the perlbal mailing list