From c24e8775bf9ff4f303e3e37cb8db1356558927ab Mon Sep 17 00:00:00 2001 From: Francis Besset Date: Thu, 14 Aug 2014 11:18:46 +0200 Subject: [PATCH] [SoapClient] Add possiblity to disable proxy if present in environment variable --- src/BeSimple/SoapClient/Curl.php | 11 ++++++++--- src/BeSimple/SoapClient/Tests/CurlTest.php | 16 ++++++++++++---- .../SoapClient/Tests/WsdlDownloaderTest.php | 4 +++- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/BeSimple/SoapClient/Curl.php b/src/BeSimple/SoapClient/Curl.php index 699e56c..7fad7a9 100644 --- a/src/BeSimple/SoapClient/Curl.php +++ b/src/BeSimple/SoapClient/Curl.php @@ -81,8 +81,13 @@ class Curl curl_setopt($this->ch, CURLOPT_CONNECTTIMEOUT, $options['connection_timeout']); } if (isset($options['proxy_host'])) { - $port = isset($options['proxy_port']) ? $options['proxy_port'] : 8080; - curl_setopt($this->ch, CURLOPT_PROXY, $options['proxy_host'] . ':' . $port); + if (false !== $options['proxy_host']) { + $proxyHost = $options['proxy_host'].(isset($options['proxy_port']) ? $options['proxy_port'] : 8080); + } else { + $proxyHost = false; + } + + curl_setopt($this->ch, CURLOPT_PROXY, $proxyHost); } if (isset($options['proxy_user'])) { curl_setopt($this->ch, CURLOPT_PROXYUSERPWD, $options['proxy_user'] . ':' . $options['proxy_password']); @@ -310,4 +315,4 @@ class Curl return trim(array_pop($matches)); } -} \ No newline at end of file +} diff --git a/src/BeSimple/SoapClient/Tests/CurlTest.php b/src/BeSimple/SoapClient/Tests/CurlTest.php index a7e8541..c80b992 100644 --- a/src/BeSimple/SoapClient/Tests/CurlTest.php +++ b/src/BeSimple/SoapClient/Tests/CurlTest.php @@ -21,7 +21,9 @@ class CurlTest extends AbstractWebserverTest { public function testExec() { - $curl = new Curl(); + $curl = new Curl(array( + 'proxy_host' => false, + )); $this->assertTrue($curl->exec(sprintf('http://localhost:%d/curl.txt', WEBSERVER_PORT))); $this->assertTrue($curl->exec(sprintf('http://localhost:%d/404.txt', WEBSERVER_PORT))); @@ -29,7 +31,9 @@ class CurlTest extends AbstractWebserverTest public function testGetErrorMessage() { - $curl = new Curl(); + $curl = new Curl(array( + 'proxy_host' => false, + )); $curl->exec('http://unknown/curl.txt'); $this->assertEquals('Could not connect to host', $curl->getErrorMessage()); @@ -43,7 +47,9 @@ class CurlTest extends AbstractWebserverTest public function testGetRequestHeaders() { - $curl = new Curl(); + $curl = new Curl(array( + 'proxy_host' => false, + )); $curl->exec(sprintf('http://localhost:%d/curl.txt', WEBSERVER_PORT)); $this->assertEquals(132 + self::$websererPortLength, strlen($curl->getRequestHeaders())); @@ -54,7 +60,9 @@ class CurlTest extends AbstractWebserverTest public function testGetResponse() { - $curl = new Curl(); + $curl = new Curl(array( + 'proxy_host' => false, + )); $curl->exec(sprintf('http://localhost:%d/curl.txt', WEBSERVER_PORT)); $this->assertSame('OK', $curl->getResponseStatusMessage()); diff --git a/src/BeSimple/SoapClient/Tests/WsdlDownloaderTest.php b/src/BeSimple/SoapClient/Tests/WsdlDownloaderTest.php index 27f419e..9597ca6 100644 --- a/src/BeSimple/SoapClient/Tests/WsdlDownloaderTest.php +++ b/src/BeSimple/SoapClient/Tests/WsdlDownloaderTest.php @@ -41,7 +41,9 @@ class WsdlDownloaderTest extends AbstractWebserverTest Cache::setDirectory($wsdlCacheUrl); $cacheDirForRegExp = preg_quote($wsdlCacheUrl, '#'); - $wsdlDownloader = new WsdlDownloader(new Curl()); + $wsdlDownloader = new WsdlDownloader(new Curl(array( + 'proxy_host' => false, + ))); $this->assertCount(0, $wsdlCacheDir->getChildren()); $cacheFileName = $wsdlDownloader->download($source);