Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re: Pass through perl http proxy server (no code, just advice)

by IlyaM (Parson)
on Mar 01, 2003 at 13:06 UTC ( #239690=note: print w/replies, xml ) Need Help??

in reply to Pass through perl http proxy server (no code, just advice)

In my attempt to learn POE I wrote this simple single-process proxy:
#!/usr/bin/perl use warnings; use strict; use POE qw(Component::Server::TCP Component::Client::HTTP Filter::HTTPD Filter::Stream); POE::Component::Client::HTTP->spawn(Alias => 'user_agent', Streaming => 1024); POE::Component::Server::TCP->new ( Alias => 'web_server', Port => 8000, ClientFilter => 'POE::Filter::HTTPD', ClientInput => \&client_input, InlineStates => { proxy_response => \&proxy_response } ); $poe_kernel->run(); sub client_input { my ($kernel, $heap, $request) = @_[KERNEL, HEAP, ARG0]; # if request is actually response it just means that we've got an # error if($request->isa('HTTP::Response')) { $heap->{client}->put($request); $kernel->yield('shutdown'); return; } $request->header(Connection => 'close'); $kernel->post(user_agent => request => proxy_response => $request) +; } sub proxy_response { my ($kernel, $heap, $request_packet, $response_packet) = @_[KERNEL, HEAP, ARG0, ARG1]; my $request = $request_packet->[0]; my ($response, $data) = @$response_packet; unless($heap->{got_headers}) { $response->header(Connection => 'close'); $heap->{client}->put($response); $heap->{got_headers}++; } if(defined $data) { $heap->{client}->set_output_filter(POE::Filter::Stream->new()) +; $heap->{client}->put($data); } else { $kernel->yield("shutdown"); } }
Note that at the time of writing it requires patched POE::Component::Client::HTTP.

Ilya Martynov,
Quality Perl Programming and Unix Support UK managed @ offshore prices -
Personal website -

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://239690]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (6)
As of 2016-10-22 08:00 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (293 votes). Check out past polls.