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

Hi Monks,
This problem is rather invovled in the nitty gritty of HTTP::Proxy. I am trying use HTTP::Proxy to proxy a large (slow) html file. The problem is that it seems to be trying to download the HTTP response before forwarding it on. At first I thought this was a property of the LWP::UserAgent, but the following code (from the cookbook) works fine:

use LWP::UserAgent; $ua = LWP::UserAgent->new; #$URL = 'http://whatever/file.html'; my $expected_length; my $bytes_received = 0; my $req = HTTP::Request->new( GET => $URL ); my $res = $ua->simple_request($req, sub { my($chunk, $res) = @_; $bytes_received += length($chunk); unless (defined $expected_length) { $expected_length = $res->content_length || 0; } if ($expected_length) { printf STDERR "%d%% - ", 100 * $bytes_received / $expected_le +ngth; } print STDERR "$bytes_received bytes received\n"; }); print $res->status_line, "\n";

Gives the output:
0% - 32 bytes received
0% - 108 bytes received
0% - 232 bytes received
etc.

So given the user agent is capable of parsing the html in chunks like this, how can I get HTTP::Proxy to do it? The source code for HTTP/Proxy.pm (sub serve_connections) seems pretty similar to my example, so I can't work out why it isn't working :(

I'm only a perl dabbler, where should I be looking for help on this type of thing? Is here a good choice? Finally can I start hacking the HTTP::Proxy module? Can I drop in a replacement HTTP/Proxy.pm but use the system version for everything else? (given that I don't have root access on this machine).

Any help greatfully appriciated!

Replies are listed 'Best First'.
Re: change HTTP::Proxy so it doesn't store-then-forward
by shmem (Chancellor) on Jun 28, 2006 at 19:04 UTC
    In reverse order:

    • you can use modules from your own filesystem space setting the environment variable PERL5LIB to some path. This path will be prepended to perl's search path - see perlrun.
    • certainly you can start hacking the HTTP::Proxy module, store the results in a path of your choice and use it, althogh I don't encourage it other than for your learning experience.
    • here is a good choice to ask for advice, and visiting this site frequently will bring you enlightenment. I suggest you to use Super Search to find nodes on your topic.
    • You claim that the source code of HTTP/Proxy.pm looks similar to your example, but alas, I cannot join you in that claim, for I do not have insight into your example. All I have is a script of yours, which proves LWP::UserAgent to be working fine.
    • Post that example, so we can help you to work out how to get HTTP::Proxy work as expected.

    regards,
    --shmem

    _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                  /\_¯/(q    /
    ----------------------------  \__(m.====·.(_("always off the crowd"))."·
    ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}