#!/usr/bin/perl -w use strict; use HTTP::Proxy qw/:log/; use HTTP::Headers ; use HTTP::Proxy::HeaderFilter; # Variable init my $host = undef; my $port = 80; my $log_file = "/tmp/proxy.log"; my $localhost = "proxy_host"; # the host where proxy is running my $remotehost = "forwarded_host"; my $agent_timeout = 10; sub search_credentials { my($iv_user,$iv_group) = @_; my($ht_user,$ht_passwd); # do some userid mapping funk # test example $ht_user = 'username'; $ht_passwd = 'password'; return ($ht_user,$ht_passwd); } open(LOG,">>", $log_file); my $proxy = HTTP::Proxy->new; $proxy->port($port); $proxy->host($host); $proxy->logfh(*LOG); #$proxy->logmask(STATUS | PROCESS ); # Normal logging $proxy->logmask(STATUS | PROCESS | HEADERS | FILTER); # Debug logging my $filter = HTTP::Proxy::HeaderFilter->new( sub { my ( $self, $headers, $message ) = @_; my $get_uri = $message->$headers->uri(); print "Unaltered URI: $get_uri\n"; my $iv_user = $message->$headers->header('iv-user'); my $iv_group = $message->$headers->header('iv-group'); my($ht_user,$ht_passwd) = search_credentials($iv_user,$iv_group); $message->$headers->authorization_basic($ht_user,$ht_passwd); $get_uri =~ s/$localhost/$remotehost/ if $get_uri =~ m/$localhost/ ; $get_uri =~ s?^/?http://$remotehost/? if $get_uri =~ m%^/% ; print "Altered URI: $get_uri\n"; $message->$headers->uri($get_uri); } ); $proxy->push_filter(request => $filter); # this is the mainloop $proxy->start; #### [Wed Dec 15 13:51:39 2004] (10600) Request: GET http://192.168.252.209/index.html [Wed Dec 15 13:51:39 2004] (10600) Request: Via: 0.9 amano (HTTP::Proxy/0.13) [Wed Dec 15 13:51:39 2004] (10600) Request: Authorization: Basic YWRtaW46bmFsaWIxNTk= #### [Wed Dec 15 15:39:56 2004] (11209) Request: GET / [Wed Dec 15 15:39:57 2004] (11209) Response: 501 Not Implemented