--- common.inc
+++ (clipboard)
@@ -443,6 +443,8 @@
 function drupal_http_request($url, $headers = array(), $method = 'GET', $data = NULL, $retry = 3) {
   global $db_prefix;
 
+  $proxy_not_required = TRUE;
+
   $result = new stdClass();
 
   // Parse the URL and make sure we can handle the schema.
@@ -465,7 +467,14 @@
     case 'feed':
       $port = isset($uri['port']) ? $uri['port'] : 80;
       $host = $uri['host'] . ($port != 80 ? ':'. $port : '');
-      $fp = @fsockopen($uri['host'], $port, $errno, $errstr, 15);
+      $proxy_not_required = is_in_no_proxy_list($uri['host']);
+      if ((variable_get('proxy_server', '') != '') && (FALSE == $proxy_not_required)) {
+        $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.
@@ -496,9 +505,14 @@
   }
 
   // Construct the path to act on.
-  $path = isset($uri['path']) ? $uri['path'] : '/';
-  if (isset($uri['query'])) {
-    $path .= '?'. $uri['query'];
+  if ((variable_get('proxy_server', '') != '') && (FALSE == $proxy_not_required)) {
+    $path = $url;
+  }
+  else {
+    $path = isset($uri['path']) ? $uri['path'] : '/';
+    if (isset($uri['query'])) {
+      $path .= '?'. $uri['query'];
+    }
   }
 
   // Create HTTP request.
@@ -534,6 +548,13 @@
     $defaults['User-Agent'] = 'User-Agent: ' . $matches[0];
   }
 
+  if ((variable_get('proxy_username', '') != '') && (FALSE == $proxy_not_required)) {
+    $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;
   }
@@ -613,6 +634,24 @@
   $result->code = $code;
   return $result;
 }
+
+function is_in_no_proxy_list($host) {
+  $rv = FALSE;
+  
+  $proxy_exceptions = variable_get('proxy_exceptions', '');
+  if (FALSE == empty($proxy_exceptions)) {
+    $patterns = explode(",",$proxy_exceptions);
+    foreach ($patterns as $pattern) {
+      $pattern = trim($pattern, " ");
+      if (strstr($host,$pattern)) {
+        $rv = TRUE;
+        break;
+      }
+    }
+  }
+  return $rv;
+}
+
 /**
  * @} End of "HTTP handling".
  */
