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

Hi Monks.
I want to write a small proxy with the capable of logging requests and responses.

The basic and perhaps often seen scriptlet looks like

my $UA = LWP::UserAgent->new; $UA->agent("Mozilla/4.0"); $UA->protocols_allowed(['http','https']); my $SRV = HTTP::Daemon->new(LocalPort => 3128); print "Please contact me at: <URL:", $SRV->url, ">\n"; while (my $conn = $SRV->accept) { while (my $request = $conn->get_request) { my $resp = $UA->simple_request($request); $conn->send_response($resp); } $conn->close; }

On my system the modules Crypt::SSLeay, openssl package and IO::Net::SSL are installed.
If I define a request-object like

my $req = new HTTP::Request('GET', 'https://www.nodeworks.com');

or get one about the HTTP::Daemon

my $req = new HTTP::Request('CONNECT', 'http://www.nodeworks.com:443');

, only the first one works.

I've read something about patching the Daemon, other people choose the way to patch http.pm - Modules, but nothing seems to work.
What is to do now, or what do I wrong? I don't want low level programming, if anyone has samplecode, please post it.

Here are some Postings, I've studied and tried them out.
If we get it to work, perhaps we should write a small howto; during my inquest I found many people who was in the same situation with no satisfactory solution.

http://www.byte.com/documents/s=493/byt20010214s0005/index3.htm
http://www.perlmonks.org/index.pl?node_id=179922
http://groups.google.de/groups?q=perl+SSL+HTTP::Daemon&hl=de&lr=&ie=UTF-8&selm=3CB9EFAF.80809%40computer.org&rnum=1

Thanks in advance and
best regards,
Andreas

Replies are listed 'Best First'.
Re: LWP, Proxy, SSL
by steves (Curate) on Nov 25, 2002 at 22:27 UTC
    I started down this path and learned some things, although maybe not enough to be 100% accurate here. A proxy by default cannot explicitly see SSL data or the security model is compromised. The CONNECT request is a request to a proxy to open a connection to a server. The idea (I think) is that the proxy can see that request, can then open a socket to the named host/port, and pass data back and forth between the client. I've seen this done by having the proxy take a CONNECT and turn it into a socket open to the server. So you can't just pass the CONNECT on as you can for other HTTP requests. Once the connection is established I'd think the proxy could dig into the data if it knows enough about the client's encryption settings to do so. Never gone that far though ...