#!/usr/local/bin/perl -w use strict; use HTTP::Proxy qw/:log/; use HTTP::Headers ; use HTTP::Proxy::HeaderFilter::simple; # Variable init my $host = undef; my $port = 80; my $log_file = "/tmp/proxy.log"; my $localhost = "proxy_host"; my $remotehost = "forwarded_host"; my $agent_timeout = 10; sub search_credentials { my($iv_user,$iv_group) = @_; my($ht_user,$ht_passwd); # test example $ht_user = 'some_web_user'; $ht_passwd = 'passwd'; 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 | HEADERS | FILTER); # Debug logging my $filter = HTTP::Proxy::HeaderFilter::simple->new( sub { my ( $self, $headers, $message ) = @_; my $get_uri = $message->uri() ? $message->uri() : "http://$remotehost/"; if( $get_uri =~ m%^/%) { print "Unaltered URI: $get_uri\n"; $get_uri =~ s?^/?http://$remotehost/? ; print "Altered URI: $get_uri\n"; } my $iv_user = $message->header('iv-user'); my $iv_group = $message->header('iv-group'); my($ht_user,$ht_passwd) = search_credentials($iv_user,$iv_group); $message->authorization_basic($ht_user,$ht_passwd); } ); $proxy->push_filter(request => $filter ); # this is the mainloop $proxy->start;