kazak has asked for the wisdom of the Perl Monks concerning the following question:

Hi 2 all. I have to implement the last but most important piece of my system - some proxy that will detect "bad responses" and repeat them through other parent proxy:

request -> http://example.com/stats ->

<- http://bl.com/Sorry=http://example.com/stats/ <- BAD response

Proxy must:

1. Detect: *Sorry* in URI returned in response

2. Cut off "http://bl.com/Sorry="

3. Repeat "http://example.com/stats/" through other proxy.

4. Return content to client.

I decided to try write it perl. But it just to hard to me with knowledges i have at this point. I found HTTP::Proxy and managed to start simple proxy-example from the CPAN ( I installed LWP::UserAgent HTTP::Daemon made #export http_proxy=http://127.0.0.1:3128/) Example:
use HTTP::Proxy; # initialisation my $proxy = HTTP::Proxy->new( port => 3128 ); # alternate initialisation my $proxy = HTTP::Proxy->new; $proxy->port( 3128 ); # the classical accessors are here! # this is a MainLoop-like method $proxy->start;
But how to move forward, what next? I just have no clue :(.

Thanks in advance.

Replies are listed 'Best First'.
Re: Proxy repeater
by onelesd (Pilgrim) on Oct 17, 2011 at 21:28 UTC
    I'd use squid to set up your proxy environment. It's tried and true and has lots of options which may help you now or later when you want additional/different behavior. Look at retry_on_error and cache_peer in squid's configuration to set up the behavior you describe.
      I'm already using it, (squid:cache_peer, roundrobin) but I need to place this repeater before squid, in order to handle "bad responses" because squid just unable to do such things.