Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Answer: How do I password-protect my HTTP::Proxy daemon?

by superfrink (Curate)
on Nov 30, 2004 at 19:59 UTC ( #411258=categorized answer: print w/replies, xml ) Need Help??

Q&A > HTTP and FTP clients > How do I password-protect my HTTP::Proxy daemon? - Answer contributed by superfrink

The following includes hints scattered through the thread login & password.

The HTTP::Proxy documentation doesn't explicitly mention "login" or "password", but it does talk about "authentication".

HTTP::Proxy does not have options to enable a password protection system; instead, you have to add a "filter" for authentication. HTTP::Proxy::HeaderFilter::simple can create such a filter.

The HTTP-Proxy distribution includes an example program,, which demonstrates how to add a BasicAuth style password to a proxy.

Below is a copy of this program with some customizations to (1) specify the port, (2) allow any IP address to use the proxy, and (3) disable some headers added by the proxy.

#!/usr/bin/perl -w use HTTP::Proxy qw( :log ); use HTTP::Proxy::HeaderFilter::simple; use MIME::Base64 qw( encode_base64 ); use strict; # the encoded user:password pair my $token = "Basic " . encode_base64( "warren:12345" ); chomp $token; # grr # a very simple proxy that requires authentication # login/password: http/proxy my $proxy = HTTP::Proxy->new; $proxy->port( 3128 ); # the classical accessors are here! $proxy->host( undef ); # allow any IP addresses. $proxy->via( '' ); # hide proxy presence. $proxy->x_forwarded_for( '' ); # hide proxy presence. # $proxy->logmask( shift || NONE ); $proxy->logmask( shift || STATUS ); # the authentication filter $proxy->push_filter( request => HTTP::Proxy::HeaderFilter::simple->new( sub { my ( $self, $headers, $request ) = @_; my $auth = $self->proxy->hop_headers->header('Proxy-Author +ization') || ''; # check the credentials if ( $auth ne $token ) { my $response = HTTP::Response->new(407); $response->header( Proxy_Authenticate => 'Basic realm= +"HTTP::Proxy"' ); $self->proxy->response($response); } } ) ); $proxy->start;

Log In?

What's my password?
Create A New User
[1nickt]: Discipulus that was the point of my story of taking the sticker off my truck. I know there are lots of people in the world who if I knw their private beliefs I might want to argue with them. And they with me. But life cannot all be arguments!
[1nickt]: This is less than perfect ... but demanding perfection (from people or from life) is a sure way to unhappiness.
[Discipulus]: and anyway we have CB where every (democratic) opinion can be expressed
erix eat the rich!
[1nickt]: I do think it is sad that roho has received 3 downvotes for his polite request, as did I when I objected to the profanity in stonecolddevin's sig. I upvoted both him and Karl for the discussion. Way too much downvoting for inappropriate reasons here!
Discipulus learn that 'argue' has a little negative sense, he thought was a neutral sense, 'vox media'
[1nickt]: argue == discuss && argue == be contentious
[Discipulus]: you are right 1nickt i didnt voted nor downvoted; I just upvote perl content i like
[1nickt]: In Spanish, to argue (like a fight) is discutir -- does not mean to discuss !
[1nickt]: Sigh, this is why I gave up human-only languages and became a Perl linguist :-)

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (7)
As of 2017-06-22 12:18 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (519 votes). Check out past polls.