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

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

by IlyaM (Parson)
on Mar 01, 2003 at 13:06 UTC ( [id://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, ilya@iponweb.net
CTO IPonWEB (UK) Ltd
Quality Perl Programming and Unix Support UK managed @ offshore prices - http://www.iponweb.net
Personal website - http://martynov.org

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (7)
As of 2024-04-24 01:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found