When using a proxy PoCo::Client::HTTP sets the Host: header to the
name and port of the proxy.  That makes it not work at all, at least
with my proxy (squid).

This patch reorders the code slightly so it works correctly.

 - ask


--- HTTP.pm~    Sat May  3 23:08:08 2003
+++ HTTP.pm     Sun Jun 29 19:48:22 2003
@@ -259,6 +259,7 @@
              and length $http_request->protocol()
            );
 
+
   # MEXNIX 2002-06-01: If we have a proxy set, and the request URI is
   # not in our no_proxy, then use the proxy.  Otherwise use the
   # request URI.
@@ -273,17 +274,8 @@
   };
   warn($@), return if $@;
 
-  if (defined $heap->{proxy} and not _in_no_proxy($host, $heap->{no_proxy})) {
-    my $proxy = $heap->{proxy}->[rand @{$heap->{proxy}}];
-    $host = $proxy->[PROXY_HOST];
-    $port = $proxy->[PROXY_PORT];
-    $using_proxy = TRUE;
-  }
-  else {
-    $using_proxy = FALSE;
-  }
-
-  # Add a host header if one isn't included.
+  # Add a host header if one isn't included.  Must do this before 
+  # we reset the $host for the proxy!
   unless ( defined $http_request->header('Host')
            and length $http_request->header('Host')
          ) {
@@ -294,6 +286,16 @@
     else {
       $http_request->header( Host => "$host:$port" )
     }
+  }
+
+  if (defined $heap->{proxy} and not _in_no_proxy($host, $heap->{no_proxy})) {
+    my $proxy = $heap->{proxy}->[rand @{$heap->{proxy}}];
+    $host = $proxy->[PROXY_HOST];
+    $port = $proxy->[PROXY_PORT];
+    $using_proxy = TRUE;
+  }
+  else {
+    $using_proxy = FALSE;
   }
 
   # Add an agent header if one isn't included.

-- 
ask bjoern hansen, http://www.askbjoernhansen.com/ !try; do();

Reply via email to