Re: anonymous proxy server in 100 lines of Perl
Gisle Aas (aas@bergen.sn.no)
24 Nov 1996 14:14:31 +0100
Randal Schwartz <merlyn@stonehenge.com> writes:
> No cookies. No referer. No From. All we need is a dozen of these
> around the planet. :-)
Cool!
I have a few comments below:
> $SIG{__DIE__} = sub { die prefix @_ };
I am not so sure that it is a good idea to set up such a __DIE__
handler since the library use eval{ ....die ...} a lot to implement
exceptions. You will confuse the catch-code that tries to match
values of $@.
> &handle_connection($slave) while $slave = $master->accept;
> exit 0;
For some reason this daemon would only handle one connection when I
tried it. I don't know why it happended.
> } elsif (not $url->rel->netloc) {
What good does the "rel" call do?
If you want to be more fancy (and efficient), you should start to send
the response back to the client before you have received all the
content from the origin server. Something like this ought to do the
trick:
$headers_sent = 0;
$ua->request($req,
sub {
my($content, $response) = @_;
unless ($headers_sent++) {
$response->remove_header(qw(Set-Cookie)); # or whatever
$connection->send_response($response);
}
$connection->print($content);
});
This should help a lot when large files pass though the proxy.
--
Gisle Aas <aas@a.sn.no>
Schibsted Nett AS http://www.sn.no/~aas/