I actually just finished some proof of concept code here to allow us to
"hide" an asp 2.0 application within a mod_perl site.  

Basically, all it does is "proxy" (faked, using LWP) the request back to
the other server as as part of content generation phase.  take the
response it gets, munges it and sends it back to the client.

This is the sub that does the faked proxying (along with a lot of debug
warn's etc).  You can then take the HTTP::Response and do whatever you
want with it (like pass though headers to the client, parse the content,
whatever).  

sub go_get_page {
    my $r = shift;
    my $page_out;
    
    my $ua = LWP::UserAgent->new;
    
    my $h = HTTP::Headers->new;
    foreach my $key (keys %{$r->headers_in}) {
        $r->warn("h_i: $key =  " .$r->headers_in->{$key}. "\n");
        unless ( $key eq 'Host' 
                 || $key eq 'Connection'
               ) {
            $h->header($key => $r->headers_in->{$key}); 
            $r->warn('included ' . $key);
        }
    }
    my $body;
    if ($r->body) {
        foreach my $key (keys %{$r->body}) {
            $r->warn("body: $key =  " .encode($r->body->{$key}));
            $body .= qq[&] if $body;
            $body .= qq[$key=].encode($r->body->{$key}) ; 
        }
    }
    $r->warn($body);
    
    my $response = $ua->request(HTTP::Request->new($r->method =>
'http://www.whatever.com' . $r->uri, $h,$body));
    
    return $response;
}

In MP1 there seemed to be something called Apache::Proxy
(http://search.cpan.org/~xfire/Apache-Proxy-0.02/Proxy.pm), but i
couldn't find something comparable for MP2.

There are a ton of caveats to this, like the thing you're proxying has
to actually play nicely for anything to work, but I actually managed
(with about 120 lines of perl and and some fiddling with the apache
conf) to get a test app written using microsoft's new magic ajax
VisualStudio nonsense to work right through this filter/proxy.  

Not sure if this is even related to what you're really trying to do or
not, but maybe it'll give you another place to start or something.

If there is actually somethign like an Apache2::Proxy out there, i'd
like to hear about it.

Adam


-----Original Message-----
From: Aaron Trevena [mailto:[EMAIL PROTECTED] 
Sent: Thursday, December 07, 2006 10:17 AM
To: modperl@perl.apache.org
Subject: Re: using subrequest to different server

On 06/12/06, Marc Lambrichs <[EMAIL PROTECTED]> wrote:
> I'm trying to change a subrequest to do a request to a different
server
> than the originating one. I'm not sure if this is possible. Anyway,
I've
> skipped the internal_redirect because - am I correct? - this is bound
to
> the originating server.
>
> My second thought was using lookup_uri(), but I'm not sure this can be
done.
>
> Ofcourse, I'm trying to avoid a normal redirect either through apache
> config, or mod_rewrite or defining a separate handler. Any ideas?

What is the context of the redirect?

Are you just fetching something and providing it as is - i.e.
proxying, if so then mod_proxy would be your friend (ProxyPass and
ProxyPassReverse are very very handy)

Otherwise, presumbably you're executing some code to do something
and/or decided if you need to proxy the content, in which case it's a
bit trickier and you may need to use LWP or something to fetch the
data yourself.

I don't know of a mod_perl way to redirect to another server, but I'd
be interested to know if it was possible.

A.

-- 
http://www.aarontrevena.co.uk
LAMP System Integration, Development and Hosting

Reply via email to