HTTP-Proxy
view release on metacpan or search on metacpan
- eg/adblock.pl - a very simple adblocker
- eg/trim.pl - trims whitespace from HTML pages
- eg/javascript.pl - add any text right after <body>
[DOCUMENTATION]
- separate COPYRIGHT and LICENSE sections in all man pages
0.12 Thu Jan 22 23:54:03 CET 2004
[ENHANCEMENTS]
- send the error message to the client when the Proxy agent dies
(usually because of a filter error)
- the proxy now sends a X-Forwarded-For header by default
(and the proxy method x_forwarded_for can toggle this)
- the proxy method client_socket() gives access to the socket
connected to the current client (the example in Changes for 0.10
was wrong: one can get the IP address of the connected agent from
inside a filter with $self->proxy->client_socket->peerhost)
[FIXES]
- do not block simultaneous connections when not forking
- clean up the filter chain after the body-request filters
- ensure the filter stack is reinitialised between requests
[TESTS]
- tests for X-Forwarded-For
- test the proxy against http://diveintomark.org/tests/client/http/
[EXAMPLES]
- eg/post.pl - outputs the URI and parameters of all POST requests
- eg/logger.pl - outputs details of GET and POST requests
0.11 Fri Jan 2 17:02:08 CET 2004
[ENHANCEMENTS]
- setting maxchild to 0 prevents forking (Jim Cromie)
- filters can now match on the query string
- hop-by-hop headers and Max-Forwards headers are correctly supported
lib/HTTP/Proxy.pm view on Meta::CPAN
The url where the proxy can be reached.
=item via
The content of the Via: header. Setting it to an empty string will
prevent its addition. (default: C<$hostname (HTTP::Proxy/$VERSION)>)
=item x_forwarded_for
If set to a true value, the proxy will send the C<X-Forwarded-For:> header.
(default: true)
=back
=head2 Connection handling methods
=over 4
=item start()
lib/HTTP/Proxy/HeaderFilter/standard.pm view on Meta::CPAN
# the Via: header
my $via = $message->protocol() || '';
if ( $self->proxy->via and $via =~ s!HTTP/!! ) {
$via .= " " . $self->proxy->via;
$headers->header(
Via => join ', ',
$message->headers->header('Via') || (), $via
);
}
# the X-Forwarded-For header
$headers->push_header(
X_Forwarded_For => $self->proxy->client_socket->peerhost )
if $message->isa( 'HTTP::Request' ) && $self->proxy->x_forwarded_for;
# make a list of hop-by-hop headers
my %h2h = map { (lc) => 1 } @hopbyhop;
my $hop = HTTP::Headers->new();
my $client = HTTP::Headers->new();
$h2h{ lc $_->[0] } = 1
for map { split_header_words($_) } $headers->header('Connection');
lib/HTTP/Proxy/HeaderFilter/standard.pm view on Meta::CPAN
=head1 METHOD
This filter implements a single method that is called automatically:
=over 4
=item filter()
Enforce RFC 2616-compliant behaviour, by adding the C<Via:> and
C<X-Forwarded-For:> headers (except when the proxy was instructed not
to add them), decrementing the C<Max-Forwards:> header and removing
the hop-by-hop and L<LWP::UserAgent> headers.
Note that the filter will automatically remove the C<Accept-Encoding>
headers if the proxy has at least one L<HTTP::Proxy::BodyFilter> filter.
(This is to ensure that the filters will receive uncompressed data.)
=back
=head1 SEE ALSO
t/50standard.t view on Meta::CPAN
);
# let's return some files when asked for them
server_next($server) for 1 .. 3;
server_next($server,
sub {
my $req = shift;
SKIP: {
skip 'FreeBSD jail does not treat localhost as 127.0.0.1', 1
if ($^O eq 'freebsd' && `sysctl -n security.jail.jailed` == 1);
is( $req->header("X-Forwarded-For"), '127.0.0.1',
"The daemon got X-Forwarded-For" );
}
return $res;
}
);
server_next( $server,
sub {
my $req = shift;
is( $req->header("X-Forwarded-For"), undef,
"The daemon didn't get X-Forwarded-For" );
return $res;
}
);
exit 0;
}
push @pids, $pid;
# run a client
t/50standard.t view on Meta::CPAN
$url =~ m!http://([^:]*)!;
print $sock "GET $url HTTP/1.0\015\012Host: $1\015\012\015\012";
# fetch and count the Client-* response headers
my @client = grep { /^Client-/ } <$sock>;
is( scalar @client, 0, "No Client-* headers sent by the proxy" );
# close the connection to the proxy
close $sock or diag "close: $!";
# X-Forwarded-For (test in the server)
$req = HTTP::Request->new( HEAD => $server->url . "x-forwarded-for" );
$res = $ua->simple_request($req);
is( $res->header( 'X-Forwarded-For' ), undef, "No X-Forwarded-For sent back" );
# yet another proxy
$proxy = HTTP::Proxy->new( port => 0, max_connections => 1, x_forwarded_for => 0 );
$proxy->init; # required to access the url later
$proxy->agent->no_proxy( URI->new( $server->url )->host );
$proxy->push_filter( response => HTTP::Proxy::HeaderFilter::simple->new(
sub { is( $_[0]->proxy->client_headers->header("Client-Response-Num"), 1,
"Client headers" ); } ) );
push @pids, fork_proxy($proxy);
# X-Forwarded-For (test in the server)
$ua->proxy( http => $proxy->url );
$req = HTTP::Request->new( HEAD => $server->url . "x-forwarded-for" );
$res = $ua->simple_request($req);
is( $res->header( 'X-Forwarded-For' ), undef, "No X-Forwarded-For sent back" );
# make sure both kids are dead
wait for @pids;
( run in 0.308 second using v1.01-cache-2.11-cpan-26ccb49234f )