<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">package Apache::ProxyPassThru;

use strict;
use LWP::UserAgent ();
use Apache::Constants ':common';

sub handler {
    my($r) = @_;
    return DECLINED unless $r-&gt;proxyreq;
    $r-&gt;handler("perl-script"); #ok, let's do it
    $r-&gt;push_handlers(PerlHandler =&gt; \&amp;proxy_handler);
    return OK;
}

sub proxy_handler {
    my($r) = @_;
    my($key,$val);

    my $request = new HTTP::Request $r-&gt;method, $r-&gt;uri;

    my(%headers_in) = $r-&gt;headers_in;
    while(($key,$val) = each %headers_in) {
	$request-&gt;header($key,$val);
    }

    my $res = (new LWP::UserAgent)-&gt;request($request);
    $r-&gt;content_type($res-&gt;header('Content-type'));
    #feed reponse back into our request_rec*
    $r-&gt;status($res-&gt;code);
    $r-&gt;status_line(join " ", $res-&gt;code, $res-&gt;message);
    $res-&gt;scan(sub {
	$r-&gt;header_out(@_);
    });

    $r-&gt;send_http_header();
    $r-&gt;print($res-&gt;content);

    return OK;
}

1;

__END__

=head1 NAME

Apache::ProxyPassThru - Skeleton for vanilla proxy

=head1 SYNOPSIS

 #httpd.conf or some such
 PerlTransHandler  Apache::ProxyPassThru


=head1 DESCRIPTION

This module uses libwww-perl as it's web client, feeding the response
back into the Apache API request_rec structure. 
`PerlHandler' will only be invoked if the request is a proxy request,
otherwise, your normal server configuration will handle the request. 

=head1 SEE ALSO

mod_perl(3), Apache(3), LWP::UserAgent(3)

=head1 AUTHOR

Doug MacEachern &lt;dougm@osf.org&gt;


</pre></body></html>