--- includes/common.inc 2008-06-11 02:12:03.000000000 +1000
+++ includes/common.inc	2008-06-28 01:05:12.000000000 +1000
@@ -439,7 +439,14 @@ function drupal_http_request($url, $head
     case 'http':
       $port = isset($uri['port']) ? $uri['port'] : 80;
       $host = $uri['host'] . ($port != 80 ? ':'. $port : '');
-      $fp = @fsockopen($uri['host'], $port, $errno, $errstr, 15);
+      if (variable_get('proxy_server', '') != '') {
+        $proxy_server = variable_get('proxy_server', '');
+	$proxy_port = variable_get('proxy_port', 8080);
+	$fp = @fsockopen($proxy_server, $proxy_port, $errno, $errstr, 15);
+      }
+      else {
+        $fp = @fsockopen($uri['host'], $port, $errno, $errstr, 15);
+      }
       break;
     case 'https':
       // Note: Only works for PHP 4.3 compiled with OpenSSL.
@@ -462,9 +469,13 @@ function drupal_http_request($url, $head
   }
 
   // Construct the path to act on.
-  $path = isset($uri['path']) ? $uri['path'] : '/';
-  if (isset($uri['query'])) {
-    $path .= '?'. $uri['query'];
+  if (variable_get('proxy_server', '') != '') {
+    $path = $url;
+  } else {
+    $path = isset($uri['path']) ? $uri['path'] : '/';
+    if (isset($uri['query'])) {
+      $path .= '?' . $uri['query'];
+    }
   }
 
   // Create HTTP request.
@@ -482,11 +493,22 @@ function drupal_http_request($url, $head
     $defaults['Authorization'] = 'Authorization: Basic '. base64_encode($uri['user'] . (!empty($uri['pass']) ? ":". $uri['pass'] : ''));
   }
 
+  // If the proxy server required a username then attempt to authenticate with it.
+  if (variable_get('proxy_username', '') != '') {
+    $username = variable_get('proxy_username', '');
+    $password = variable_get('proxy_password', '');
+    $auth_string = base64_encode($username . ($password != '' ? ':'. $password : ''));
+    $defaults['Proxy-Authorization'] = 'Proxy-Authorization: Basic '. $auth_string ."\r\n";
+  }
+
   foreach ($headers as $header => $value) {
     $defaults[$header] = $header .': '. $value;
   }
 
-  $request = $method .' '. $path ." HTTP/1.0\r\n";
+  $request = $method .' '. $path ." HTTP/1.1\r\n";
+  if (variable_get('proxy_username', '') != '') {
+    $request .= 'Proxy-Authorization: Basic ' . base64_encode("$username:$password") . "\r\n";
+  }
   $request .= implode("\r\n", $defaults);
   $request .= "\r\n\r\n";
   if ($data) {
