Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^4: HTTP::Proxy and X-Forwarded-For headers

by cleverett (Friar)
on Sep 13, 2004 at 22:43 UTC ( [id://390691]=note: print w/replies, xml ) Need Help??


in reply to Re^3: HTTP::Proxy and X-Forwarded-For headers
in thread HTTP::Proxy and X-Forwarded-For headers

I have the proxy at localhost:1081, using the proxy setting in the browser.

I should post the code to my proxy:

#!/usr/bin/perl ## ## live-test-proxy.pl ## use strict; use warnings; my $port = 1081; my $file = './http-proxy-recording.pl'; use HTTP::Proxy; use HTTP::Recorder; # create a new HTTP::Recorder object my $agent = HTTP::Recorder->new(file => $file); # create proxy and configure my $proxy = HTTP::Proxy->new(); $proxy->port($port); $proxy->agent( $agent ); # set HTTP::Recorder as the a +gent for the proxy $proxy->x_forwarded_for(0); $proxy->push_filter( host => 'ceverett.medbanner.com', path => '/cgi-bin/', request => EngineTestFilter->new(), ); # start the proxy $proxy->start(); package EngineTestFilter; use base qw/HTTP::Proxy::HeaderFilter/; use strict; use warnings; use Data::Dumper; sub filter { my ($self, $headers, $request) = @_; my $uri = $request->uri(); my ($location, $query) = split(/\?/, $uri); my %params = map { split /=/ } map { split /&/ } $query; $request->uri($location .'?'.join('&', map { "$_=$params{$_}" } qw/ +a s/)); $headers->header(Referer => $params{referer}); $headers->remove_header('X-Forwarded-For'); $headers->header('X-Forwarded-For' => $params{remote_ip}); } 1;

Replies are listed 'Best First'.
Re^5: HTTP::Proxy and X-Forwarded-For headers
by tachyon (Chancellor) on Sep 13, 2004 at 22:49 UTC

    This proxy is making the connection to Apache. As such its IP is the remote_ip as far as Apache is concerned. See mod_extract_forwarded link that explains this and how to get Apache to accept the first non truscted proxy in the X-Forwarded-For list as the remote_ip.

    cheers

    tachyon

      I took a look at mod_extract_forwarded. I'm not ready yet to move everything to mod_perl 2.0 yet, at least not until the 1.x compatibility mode works. I set mod_rpaf to treat 10.0.0.50 as a proxy server, but now the remote IP I want doesn't show up in the headers. Sigh.

        Why not just use the logic for fingering the remote IP as detailed before. In Apache syntax it would be:

        my $ip = $r->headers_in->get('X-Forwarded-For') || $r->get_remote_host() || $r->connection->remote_ip(); ($ip) = split /\s*,/, $ip;

        cheers

        tachyon

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://390691]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (5)
As of 2024-03-29 10:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found