diff --git includes/common.inc includes/common.inc index 9fc82bb..7657ccc 100644 --- includes/common.inc +++ includes/common.inc @@ -784,6 +784,21 @@ function drupal_http_request($url, array $options = array()) { $result->code = -1002; return $result; } + // Proxy setup - normal sites don't need a proxy. + $proxy_server = variable_get('proxy_server', ''); + if ($proxy_server && _drupal_http_use_proxy($uri['host'])) { + // Since the url is passed as the path, we won't use the parsed values. + $uri = array(); + // We assume all proxy communication is over http. + $uri['scheme'] = 'http'; + $uri['host'] = $proxy_server; + $uri['port'] = variable_get('proxy_port', 8080); + $uri['path'] = $url; + if ($proxy_username = variable_get('proxy_username', '')) { + $proxy_password = variable_get('proxy_password', ''); + $options['headers']['Proxy-Authorization'] = 'Basic ' . base64_encode($proxy_username . (!empty($proxy_password) ? ":" . $proxy_password : '')); + } + } timer_start(__FUNCTION__); @@ -1022,6 +1037,18 @@ function drupal_http_request($url, array $options = array()) { return $result; } + +/** + * Helper function for determining hosts excluded from needing a proxy. + * + * @return + * TRUE if a proxy should be used for this host. + */ +function _drupal_http_use_proxy($host) { + $proxy_exceptions = variable_get('proxy_exceptions', array('localhost', '127.0.0.1')); + return !in_array(strtolower($host), $proxy_exceptions, TRUE); +} + /** * @} End of "HTTP handling". */ diff --git sites/default/default.settings.php sites/default/default.settings.php index d1bb23a..ff08992 100644 --- sites/default/default.settings.php +++ sites/default/default.settings.php @@ -429,3 +429,18 @@ ini_set('session.cookie_lifetime', 2000000); * Remove the leading hash signs to disable. */ # $conf['allow_authorize_operations'] = FALSE; + +/** + * External access proxy settings: + * + * If your site must access the internet via a web proxy then you can enter + * the proxy settings here. Currently only basic authentication is supported + * by using the username and password variables. The proxy_exceptions variable + * is an array of host names to be accessed directly, not via proxy. + */ +# $conf['proxy_server'] = ''; +# $conf['proxy_port'] = 8080; +# $conf['proxy_username'] = ''; +# $conf['proxy_password'] = ''; +# $conf['proxy_exceptions'] = array('127.0.0.1', 'localhost'); +