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

Gisle Aas (gisle@activestate.com)
14 Mar 2001 13:00:57 -0800


The patch I checked in is this one:

Index: lib/HTTP/Daemon.pm
===================================================================
RCS file: /cvsroot/libwww-perl/lwp5/lib/HTTP/Daemon.pm,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -p -u -r1.23 -r1.24
--- lib/HTTP/Daemon.pm	2001/03/08 18:13:37	1.23
+++ lib/HTTP/Daemon.pm	2001/03/14 20:59:32	1.24
@@ -250,8 +250,12 @@ sub get_request
 	$self->reason("Bad request line: $buf");
 	return;
     }
+    my $method = $1;
+    my $uri = $2;
     my $proto = $3 || "HTTP/0.9";
-    my $r = HTTP::Request->new($1, $HTTP::URI_CLASS->new($2, $self->daemon->url));
+    $uri = "http://$uri" if $method eq "CONNECT";
+    $uri = $HTTP::URI_CLASS->new($uri, $self->daemon->url);
+    my $r = HTTP::Request->new($method, $uri);
     $r->protocol($proto);
     ${*$self}{'httpd_client_proto'} = $proto = _http_version($proto);
 
Regards,
Gisle



merlyn@stonehenge.com (Randal L. Schwartz) writes:

> 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!