Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

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, 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


Comment on Re: Pass through perl http proxy server (no code, just advice)
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (8)
As of 2014-09-16 11:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (13 votes), past polls