PROXY  WHOIS  RQUOTE  TEXTS  SOFT  FOREX  BBOARD
 Music  Philosophy  Code  Literature  Russian

= ROOT|Technical|Code_Examples|Perl|Proxy|simple_http_proxy.pl =

page 1 of 1



#!/usr/bin/perl

use HTTP::Daemon;
use HTTP::Status;
use LWP::UserAgent;

our $UA;
our $DAEMON = HTTP::Daemon->new(LocalPort => 8080) || die $!;

sub term {
 my $signame=shift;
 print STDERR "Signal $signame received. Terminating.\n";
 exit(0);
}

$SIG{INT} = \&term;
$SIG{BREAK} = \&term;

print STDERR "Contact proxy at: <URL:", $DAEMON->url, ">, press ^C to terminate\n";
while (my ($c, $peeraddr) = $DAEMON->accept) {
 my ($rport, $raddr) = sockaddr_in($peeraddr);
 print STDOUT 'From: ',inet_ntoa($raddr),":$rport\n";
 while (my $r = $c->get_request){
  print STDOUT $r->as_string,"\n";
  unless ($UA){
   $UA= LWP::UserAgent->new(
    'agent'=>'ProxyAgent (Mozilla 9.0; compatible)',
    'timeout' => 20,
   );
   $UA->env_proxy;
  }
  $c->send_response($UA->request($r));
 }
 $c->close;
 undef($c);
}
=1=
THE END

<<< SINGLE PAGE >>>

UP TO ROOT | UP TO DIR

Google
 

E-mail Facebook Google Digg del.icio.us BlinkList Fark Furl Ma.gnolia Netscape NewsVine Reddit Slashdot Spurl StumbleUpon Technorati YahooMyWeb LiveJournal Blogmarks TwitThis Live News2.ru BobrDobr.ru Memori.ru MoeMesto.ru

0.00455999 wallclock secs ( 0.00 usr + 0.00 sys = 0.00 CPU)