[patch] hacking HTTP::Daemon to handle CONNECT properly

Randal L. Schwartz (merlyn@stonehenge.com)
04 Mar 2001 14:07:07 -0800


HTTP::Daemon 1.22 ->get_request passes the URL-like string following
the method to make a relative based URL.  For "CONNECT" methods, this
is wrong, since no scheme is present and a hostname:port combo can
sometimes look like a scheme:hostname combo.

My patch is a bit of a hack, adding in the "telnet:" scheme when
CONNECT is used, but it seems to work nicely with the proxy server I'm
creating.

The non-upward compatibility warning is that you must now call
$request->url->host_port to get the host/port string for CONNECT,
rather than calling $request->url and using the entire string.  Since
I'm probably one of three people in the world doing this, I think it's
probably safe to just document that. :)

Here's the patch:

--- /usr/lib/perl5/site_perl/5.005/HTTP/Daemon.pm	Thu Jan  4 13:43:10 2001
+++ Daemon.pm	Sun Mar  4 13:50:22 2001
@@ -253,7 +253,11 @@
 	return;
     }
     my $proto = $3 || "HTTP/0.9";
-    my $r = HTTP::Request->new($1, $HTTP::URI_CLASS->new($2, $self->daemon->url));
+    my $r = 
+      HTTP::Request->new($1,
+			 $1 eq "CONNECT" ?
+			 $HTTP::URI_CLASS->new("telnet://$2") :
+			 $HTTP::URI_CLASS->new($2, $self->daemon->url));
     $r->protocol($proto);
     ${*$self}{'httpd_client_proto'} = $proto = _http_version($proto);


-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!