You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by JT Smith <jt...@plainblack.com> on 2005/11/17 00:32:00 UTC

special proxy mp handler

I'd like to write a handler that would serve big files out of a local cache but proxy 
everything else through to another server. The situation is that there is an extranet in 
the US, but a lot of folks in New Zealand need access to the file downloads. I don't 
want to replicate the whole installation in NZ, but instead, give them a seperate server 
with mod_proxy set up so that when they request most pages it proxies them through from 
the main server, but when they ask for a really big file in the /uploads path that it 
can pull it out of local cache.

Here's what I have so far:

package CacheHandler;

use Apache2::Request;
use Apache2::Const;

sub handler {
	my $r = shift;
	if ($r->uri =~ m/^\/uploads/) {
		my $path = "/data/cache".$r->uri;
		if (-f $path) {
	           # make it serve up this local file since it exists
		}
	}
	return Apache2::Const::DECLINED;
}

1;

And here's the virtual host I've set up:

<VirtualHost *:80>
ServerName extranet
SSLProxyEngine on
DocumentRoot "/data/cache"
ProxyPass / https://example.com/
PerlModule CacheHandler
PerlInitHandler CacheHandler
</VirtualHost>

What can I add into my handler to make it circumvent the ProxyPass directive? Or if I 
can't do that, how can I tell it to enable ProxyPass on any request where I don't pass 
those other conditions?

Thanks for any assistance you can provide in advance.

JT ~ Plain Black
ph: 703-286-2525 ext. 810
fax: 312-264-5382
http://www.plainblack.com

I reject your reality, and substitute my own. ~ Adam Savage

Re: special proxy mp handler

Posted by JT Smith <jt...@plainblack.com>.
You rock! Thank you very much.


On Wed, 16 Nov 2005 15:58:40 -0800
  "Philippe M. Chiasson" <go...@ectoplasm.org> wrote:
> JT Smith wrote:
>> I'd like to write a handler that would serve big files out of a local
>> cache but proxy everything else through to another server. The situation
>> is that there is an extranet in the US, but a lot of folks in New
>> Zealand need access to the file downloads. I don't want to replicate the
>> whole installation in NZ, but instead, give them a seperate server with
>> mod_proxy set up so that when they request most pages it proxies them
>> through from the main server, but when they ask for a really big file in
>> the /uploads path that it can pull it out of local cache.
>> 
>> Here's what I have so far:
>> 
>> package CacheHandler;
>> 
>> use Apache2::Request;
>> use Apache2::Const;
>> 
>> sub handler {
>>     my $r = shift;
>>     if ($r->uri =~ m/^\/uploads/) {
>>         my $path = "/data/cache".$r->uri;
>>         if (-f $path) {
>>                # make it serve up this local file since it exists
>>         }
>>     }
>      else {
>  	  my $real_url = $r->unparsed_uri;
>          $r->proxyreq(1);
>          $r->uri($real_url);
>  	  $r->filename("proxy:$real_url");
>          $r->handler('proxy-server');
>      }
>>     return Apache2::Const::DECLINED;
>> }
>> 
>> 1;
> 
> And then you don't need ProxyPass anymore.
> 
> See http://perl.apache.org/docs/2.0/api/Apache2/RequestRec.html#C_proxyreq_ for
> more details
> 
>> And here's the virtual host I've set up:
>> 
>> <VirtualHost *:80>
>> ServerName extranet
>> SSLProxyEngine on
>> DocumentRoot "/data/cache"
>> ProxyPass / https://example.com/
>> PerlModule CacheHandler
>> PerlInitHandler CacheHandler
>> </VirtualHost>
>> 
>> What can I add into my handler to make it circumvent the ProxyPass
>> directive? Or if I can't do that, how can I tell it to enable ProxyPass
>> on any request where I don't pass those other conditions?
>> 
>> Thanks for any assistance you can provide in advance.
> 
> --------------------------------------------------------------------------------
> Philippe M. Chiasson m/gozer\@(apache|cpan|ectoplasm)\.org/ GPG KeyID : 88C3A5A5
> http://gozer.ectoplasm.org/     F9BF E0C2 480E 7680 1AE5 3631 CB32 A107 88C3A5A5


JT ~ Plain Black
ph: 703-286-2525 ext. 810
fax: 312-264-5382
http://www.plainblack.com

I reject your reality, and substitute my own. ~ Adam Savage

Re: special proxy mp handler

Posted by "Philippe M. Chiasson" <go...@ectoplasm.org>.
JT Smith wrote:
> I'd like to write a handler that would serve big files out of a local
> cache but proxy everything else through to another server. The situation
> is that there is an extranet in the US, but a lot of folks in New
> Zealand need access to the file downloads. I don't want to replicate the
> whole installation in NZ, but instead, give them a seperate server with
> mod_proxy set up so that when they request most pages it proxies them
> through from the main server, but when they ask for a really big file in
> the /uploads path that it can pull it out of local cache.
> 
> Here's what I have so far:
> 
> package CacheHandler;
> 
> use Apache2::Request;
> use Apache2::Const;
> 
> sub handler {
>     my $r = shift;
>     if ($r->uri =~ m/^\/uploads/) {
>         my $path = "/data/cache".$r->uri;
>         if (-f $path) {
>                # make it serve up this local file since it exists
>         }
>     }
      else {
  	  my $real_url = $r->unparsed_uri;
          $r->proxyreq(1);
          $r->uri($real_url);
  	  $r->filename("proxy:$real_url");
          $r->handler('proxy-server');
      }
>     return Apache2::Const::DECLINED;
> }
> 
> 1;

And then you don't need ProxyPass anymore.

See http://perl.apache.org/docs/2.0/api/Apache2/RequestRec.html#C_proxyreq_ for
more details

> And here's the virtual host I've set up:
> 
> <VirtualHost *:80>
> ServerName extranet
> SSLProxyEngine on
> DocumentRoot "/data/cache"
> ProxyPass / https://example.com/
> PerlModule CacheHandler
> PerlInitHandler CacheHandler
> </VirtualHost>
> 
> What can I add into my handler to make it circumvent the ProxyPass
> directive? Or if I can't do that, how can I tell it to enable ProxyPass
> on any request where I don't pass those other conditions?
> 
> Thanks for any assistance you can provide in advance.

--------------------------------------------------------------------------------
Philippe M. Chiasson m/gozer\@(apache|cpan|ectoplasm)\.org/ GPG KeyID : 88C3A5A5
http://gozer.ectoplasm.org/     F9BF E0C2 480E 7680 1AE5 3631 CB32 A107 88C3A5A5