Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. #!/usr/bin/perl
  2. # Simple HTTP Proxy Program using HTTP::Daemon.
  3. # (c) 2007 by Takaki Makino http://www.snowelm.com/~t/
  4.  
  5. use strict;
  6.  
  7. use HTTP::Daemon;
  8. use LWP::UserAgent;
  9.  
  10. my $ua = LWP::UserAgent->new();
  11. my $d = HTTP::Daemon->new(
  12. LocalHost => "localhost", # remove this to listen from other machines
  13. # (i.e. open-relay... be careful of spammers!)
  14. LocalPort => 5000
  15. ) || die;
  16. print "[Proxy URL:", $d->url, "]\n";
  17.  
  18. # Avoid dying from browser cancel
  19. $SIG{PIPE} = 'IGNORE';
  20.  
  21. # Dirty pre-fork implementation
  22. fork(); fork(); fork(); # 2^3 = 8 processes
  23.  
  24. while (my $c = $d->accept) {
  25. while (my $request = $c->get_request) {
  26. print $c->sockhost . ": " . $request->uri->as_string . "\n";
  27.  
  28. $request->push_header( Via => "1.1 ". $c->sockhost );
  29. my $response = $ua->simple_request( $request );
  30.  
  31. $c->send_response( $response );
  32.  
  33. # Save the response content into file
  34. if( ($request->method eq "GET" || $request->method eq "POST")
  35. && $response->is_success && length($response->content) > 10 )
  36. {
  37. my $uri = $request->uri->as_string;
  38. $uri =~ s#/#_#g;
  39. open(F, ">$uri") || print "Cannot write $uri\n";;
  40. print F $response->content;
  41. close F;
  42. }
  43. }
  44. $c->close;
  45. undef($c);
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement