Perlbal and Rails

Cal Henderson calh at yahoo-inc.com
Thu Feb 22 01:34:43 UTC 2007


Philip Murray <pmurray at nevada.net.nz> wrote:
: Basically, if the file exists locally serve it. If it doesn't exist
: locally, proxy it to one of the backends.
:
: In a sense this is kind of combining the web_server role with the
: reverse_proxy role, is it curently possible to do this with Perlbal?


you can fairly easily do this by adding a hook to a web server backend 
(via a custom plugin) to check for 404's (the hook is called 
static_get_poststat_file_missing) and then move the request over to a 
proxy backend.

something like (untested):

------------------------------------------------------------------

package Perlbal::Plugin::Thinger;

use strict;
use warnings;

sub register {
 my ($class, $svc) = @_;

 $svc->register_hook('MyHook', 'static_get_poststat_file_missing', sub 
{

  my ($cb) = @_;

  my $new_svc = Perlbal->service('my_proxy_service');

  $new_svc->adopt_base_client($cb);

  return 1;
 });

 return 1;
}


sub unregister {
 my ($class, $svc) = @_;

 $svc->unregister_hooks('MyHook');

 return 1;
}

------------------------------------------------------------------


--cal 



More information about the perlbal mailing list