From: Evan Prodromou <evan@status.net>
Date: Mon, 3 Jan 2011 18:38:32 +0000 (-0800)
Subject: Configuration options for using an HTTP proxy
X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=98a0d7f538bad0b365adb1ec7eacb8c86c15384b;p=quix0rs-gnu-social.git

Configuration options for using an HTTP proxy

We can make a lot of HTTP requests from the server side. This change
adds some configuration options for using an HTTP proxy, which can
cache hits from multiple sites (good for status.net-like services, for example).
---

diff --git a/README b/README
index e2e4c580ef..d972bf5676 100644
--- a/README
+++ b/README
@@ -1556,6 +1556,22 @@ cache: whether to cache the router in memcache (or another caching
     router cached) or others who see strange behavior. You're unlikely
     to need this unless you're a developer.
 
+http
+----
+
+Settings for the HTTP client.
+
+ssl_cafile: location of the CA file for SSL. If not set, won't verify
+	    SSL peers. Default unset.
+curl: Use cURL <http://curl.haxx.se/> for doing HTTP calls. You must
+      have the PHP curl extension installed for this to work.
+proxy_host: Host to use for proxying HTTP requests. If unset, doesn't
+	    do any HTTP proxy stuff. Default unset.
+proxy_port: Port to use to connect to HTTP proxy host. Default null.
+proxy_user: Username to use for authenticating to the HTTP proxy. Default null.
+proxy_password: Password to use for authenticating to the HTTP proxy. Default null.
+proxy_auth_scheme: Scheme to use for authenticating to the HTTP proxy. Default null.
+
 Plugins
 =======
 
diff --git a/lib/default.php b/lib/default.php
index 6d57c4ef02..ce61de5ea5 100644
--- a/lib/default.php
+++ b/lib/default.php
@@ -331,6 +331,11 @@ $default =
         'http' => // HTTP client settings when contacting other sites
         array('ssl_cafile' => false, // To enable SSL cert validation, point to a CA bundle (eg '/usr/lib/ssl/certs/ca-certificates.crt')
               'curl' => false, // Use CURL backend for HTTP fetches if available. (If not, PHP's socket streams will be used.)
+              'proxy_host' => null,
+              'proxy_port' => null,
+              'proxy_user' => null,
+              'proxy_password' => null,
+              'proxy_auth_scheme' => null,
               ),
 	'router' =>
 	array('cache' => true), // whether to cache the router object. Defaults to true, turn off for devel
diff --git a/lib/httpclient.php b/lib/httpclient.php
index 514a5afeb2..04e2b9ac65 100644
--- a/lib/httpclient.php
+++ b/lib/httpclient.php
@@ -149,6 +149,14 @@ class HTTPClient extends HTTP_Request2
             $this->config['adapter'] = 'HTTP_Request2_Adapter_Curl';
         }
 
+        foreach (array('host', 'port', 'user', 'password', 'auth_scheme') as $cf) {
+            $k = 'proxy_'.$cf;
+            $v = common_config('http', $k); 
+            if (!empty($v)) {
+                $this->config[$k] = $v;
+            }
+        }
+
         parent::__construct($url, $method, $config);
         $this->setHeader('User-Agent', $this->userAgent());
     }