-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path7881-proxy-please-341.patch
118 lines (114 loc) · 4.24 KB
/
7881-proxy-please-341.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
diff --git a/includes/common.inc b/includes/common.inc
index b6ea297..5740e07 100644
--- a/includes/common.inc
+++ b/includes/common.inc
@@ -778,8 +778,6 @@ function drupal_http_request($url, array $options = array()) {
return $result;
}
- timer_start(__FUNCTION__);
-
// Merge the default options.
$options += array(
'headers' => array(),
@@ -789,10 +787,50 @@ function drupal_http_request($url, array $options = array()) {
'timeout' => 30.0,
'context' => NULL,
);
+ // Merge the default headers.
+ $options['headers'] += array(
+ 'User-Agent' => 'Drupal (+http://drupal.org/)',
+ );
// stream_socket_client() requires timeout to be a float.
$options['timeout'] = (float) $options['timeout'];
+ // 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 query.
+ unset($uri['query']);
+ $uri['path'] = $url;
+ // Set the scheme so we open a socket to the proxy server.
+ $uri['scheme'] = 'proxy';
+ 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 : ''));
+ }
+ // Some proxies reject requests with any User-Agent headers, while others
+ // require a specific one.
+ $proxy_user_agent = variable_get('proxy_user_agent', '');
+ // The default value matches neither condition.
+ if ($proxy_user_agent === NULL) {
+ unset($options['headers']['User-Agent']);
+ }
+ elseif ($proxy_user_agent) {
+ $options['headers']['User-Agent'] = $proxy_user_agent;
+ }
+ }
+
+ timer_start(__FUNCTION__);
+
switch ($uri['scheme']) {
+ case 'proxy':
+ // Make the socket connection to a proxy server.
+ $socket = 'tcp://' . $proxy_server . ':' . variable_get('proxy_port', 8080);
+ $port = '';
+ if (isset($uri['port']) && $uri['port'] != 80) {
+ $port = ':' . $uri['port'];
+ }
+ // The Host header still needs to match the real request.
+ $options['headers']['Host'] = $uri['host'] . $port;
+ break;
case 'http':
case 'feed':
$port = isset($uri['port']) ? $uri['port'] : 80;
@@ -844,11 +882,6 @@ function drupal_http_request($url, array $options = array()) {
$path .= '?' . $uri['query'];
}
- // Merge the default headers.
- $options['headers'] += array(
- 'User-Agent' => 'Drupal (+http://drupal.org/)',
- );
-
// Only add Content-Length if we actually have any content or if it is a POST
// or PUT request. Some non-standard servers get confused by Content-Length in
// at least HEAD/GET requests, and Squid always requires Content-Length in
@@ -1017,6 +1050,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 a/sites/default/default.settings.php b/sites/default/default.settings.php
index 0472f02..35482a0 100644
--- a/sites/default/default.settings.php
+++ b/sites/default/default.settings.php
@@ -442,3 +442,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');
+