[SoapClient] Add possiblity to disable proxy if present in environment variable

This commit is contained in:
Francis Besset 2014-08-14 11:18:46 +02:00
parent b3c6353af8
commit c24e8775bf
3 changed files with 23 additions and 8 deletions

View File

@ -81,8 +81,13 @@ class Curl
curl_setopt($this->ch, CURLOPT_CONNECTTIMEOUT, $options['connection_timeout']); curl_setopt($this->ch, CURLOPT_CONNECTTIMEOUT, $options['connection_timeout']);
} }
if (isset($options['proxy_host'])) { if (isset($options['proxy_host'])) {
$port = isset($options['proxy_port']) ? $options['proxy_port'] : 8080; if (false !== $options['proxy_host']) {
curl_setopt($this->ch, CURLOPT_PROXY, $options['proxy_host'] . ':' . $port); $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'])) { if (isset($options['proxy_user'])) {
curl_setopt($this->ch, CURLOPT_PROXYUSERPWD, $options['proxy_user'] . ':' . $options['proxy_password']); curl_setopt($this->ch, CURLOPT_PROXYUSERPWD, $options['proxy_user'] . ':' . $options['proxy_password']);
@ -310,4 +315,4 @@ class Curl
return trim(array_pop($matches)); return trim(array_pop($matches));
} }
} }

View File

@ -21,7 +21,9 @@ class CurlTest extends AbstractWebserverTest
{ {
public function testExec() 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/curl.txt', WEBSERVER_PORT)));
$this->assertTrue($curl->exec(sprintf('http://localhost:%d/404.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() public function testGetErrorMessage()
{ {
$curl = new Curl(); $curl = new Curl(array(
'proxy_host' => false,
));
$curl->exec('http://unknown/curl.txt'); $curl->exec('http://unknown/curl.txt');
$this->assertEquals('Could not connect to host', $curl->getErrorMessage()); $this->assertEquals('Could not connect to host', $curl->getErrorMessage());
@ -43,7 +47,9 @@ class CurlTest extends AbstractWebserverTest
public function testGetRequestHeaders() public function testGetRequestHeaders()
{ {
$curl = new Curl(); $curl = new Curl(array(
'proxy_host' => false,
));
$curl->exec(sprintf('http://localhost:%d/curl.txt', WEBSERVER_PORT)); $curl->exec(sprintf('http://localhost:%d/curl.txt', WEBSERVER_PORT));
$this->assertEquals(132 + self::$websererPortLength, strlen($curl->getRequestHeaders())); $this->assertEquals(132 + self::$websererPortLength, strlen($curl->getRequestHeaders()));
@ -54,7 +60,9 @@ class CurlTest extends AbstractWebserverTest
public function testGetResponse() public function testGetResponse()
{ {
$curl = new Curl(); $curl = new Curl(array(
'proxy_host' => false,
));
$curl->exec(sprintf('http://localhost:%d/curl.txt', WEBSERVER_PORT)); $curl->exec(sprintf('http://localhost:%d/curl.txt', WEBSERVER_PORT));
$this->assertSame('OK', $curl->getResponseStatusMessage()); $this->assertSame('OK', $curl->getResponseStatusMessage());

View File

@ -41,7 +41,9 @@ class WsdlDownloaderTest extends AbstractWebserverTest
Cache::setDirectory($wsdlCacheUrl); Cache::setDirectory($wsdlCacheUrl);
$cacheDirForRegExp = preg_quote($wsdlCacheUrl, '#'); $cacheDirForRegExp = preg_quote($wsdlCacheUrl, '#');
$wsdlDownloader = new WsdlDownloader(new Curl()); $wsdlDownloader = new WsdlDownloader(new Curl(array(
'proxy_host' => false,
)));
$this->assertCount(0, $wsdlCacheDir->getChildren()); $this->assertCount(0, $wsdlCacheDir->getChildren());
$cacheFileName = $wsdlDownloader->download($source); $cacheFileName = $wsdlDownloader->download($source);