diff --git a/libraries/http_request.inc b/libraries/http_request.inc index 1ed19c2218b963965ad717f9781d6b91fa9fc872..9a2629d932a27fa05f3bd8ff86e3359ed497a93c 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);