From ddee3f9fcc7ffeef5c64d3e9ecb36a91ac800a9d Mon Sep 17 00:00:00 2001
From: VladimirAus <VladimirAus@673120.no-reply.drupal.org>
Date: Fri, 5 Jul 2013 22:38:07 -0700
Subject: [PATCH] Issue #1159806 by VladimirAus, bigjim | Slim Pickens: Added
 proxy support.

---
 libraries/http_request.inc | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/libraries/http_request.inc b/libraries/http_request.inc
index 1ed19c22..9a2629d9 100644
--- a/libraries/http_request.inc
+++ b/libraries/http_request.inc
@@ -178,6 +178,22 @@ function http_request_get($url, $username = NULL, $password = NULL, $accept_inva
       curl_setopt($download, CURLOPT_RETURNTRANSFER, TRUE);
       curl_setopt($download, CURLOPT_ENCODING, '');
       curl_setopt($download, CURLOPT_TIMEOUT, $request_timeout);
+
+      $proxy_server = variable_get('proxy_server');
+
+      if ($proxy_server && _drupal_http_use_proxy($uri['host'])) {
+        curl_setopt($download, CURLOPT_PROXY, $proxy_server);
+        curl_setopt($download, CURLOPT_PROXYPORT, variable_get('proxy_port', 8080));
+
+        // Proxy user/password.
+        if ($proxy_username = variable_get('proxy_username')) {
+          $username_password = $proxy_username . ':' . variable_get('proxy_password', '');
+
+          curl_setopt($download, CURLOPT_PROXYUSERPWD, $username_password);
+          curl_setopt($download, CURLOPT_PROXYAUTH, variable_get('proxy_auth_method', CURLAUTH_BASIC));
+        }
+      }
+
       if ($accept_invalid_cert) {
         curl_setopt($download, CURLOPT_SSL_VERIFYPEER, 0);
       }
@@ -193,6 +209,18 @@ function http_request_get($url, $username = NULL, $password = NULL, $accept_inva
         );
       }
 
+      // When using a proxy, remove extra data from the header which is not
+      // considered by CURLINFO_HEADER_SIZE (possibly cURL bug).
+      // This data is only added when to HTTP header when working with a proxy.
+      // Example string added: <HTTP/1.0 200 Connection established\r\n\r\n>
+      if ($proxy_server && _drupal_http_use_proxy($uri['host'])) {
+        $http_header_break = "\r\n\r\n";
+        $response = explode($http_header_break, $data);
+        if (count($response) > 2) {
+          $data = substr($data, strlen($response[0] . $http_header_break), strlen($data));
+        }
+      }
+
       $header_size = curl_getinfo($download, CURLINFO_HEADER_SIZE);
       $header = substr($data, 0, $header_size - 1);
       $result->data = substr($data, $header_size);
-- 
GitLab