Permalink
Browse files

added proxy support

  • Loading branch information...
1 parent 03642f8 commit 98b850f650ce7b4de6b87363993d123b06cf36f5 @kriswallsmith committed Feb 24, 2013
View
@@ -2,19 +2,19 @@ language: php
php:
- 5.3.3
- - 5.4
+ # - 5.4
-env: TEST_SERVER="http://localhost:8080/server.php"
+env: TEST_SERVER="http://127.0.0.1:8080/server.php" TEST_PROXY="127.0.0.1:3128"
before_install:
- echo "" | sudo add-apt-repository ppa:nginx/stable > /dev/null 2>&1
- sudo apt-get -qq update
- - sudo apt-get -qq install nginx
- - php-cgi -b 127.0.0.1:9000 &
- - sudo nginx -p test -c nginx.conf.dist
+ - sudo apt-get -qq install nginx squid
+ - sudo stop squid3
before_script:
+ - php-cgi -b 127.0.0.1:9000 &
+ - sudo nginx -p test -c nginx.conf.dist
+ - sudo squid3 -f test/squid.conf
- composer self-update
- - composer install --dev
-
-script: ./bin/phpunit
+ - composer install
View
@@ -15,9 +15,6 @@
"require": {
"php": ">=5.3.0"
},
- "require-dev": {
- "phpunit/phpunit": "3.7.*"
- },
"suggest": {
"ext-curl": "*"
},
@@ -8,6 +8,7 @@
protected $maxRedirects = 5;
protected $timeout = 5;
protected $verifyPeer = true;
+ protected $proxy;
public function setIgnoreErrors($ignoreErrors)
{
@@ -48,4 +49,14 @@ public function getVerifyPeer()
{
return $this->verifyPeer;
}
+
+ public function setProxy($proxy)
+ {
+ $this->proxy = $proxy;
+ }
+
+ public function getProxy()
+ {
+ return $this->proxy;
+ }
}
@@ -186,6 +186,11 @@ protected function prepare($curl, RequestInterface $request, array $options = ar
} else {
curl_setopt($curl, CURLOPT_TIMEOUT, $this->getTimeout());
}
+
+ if ($this->proxy) {
+ curl_setopt($curl, CURLOPT_PROXY, $this->proxy);
+ }
+
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 0 < $this->getMaxRedirects());
curl_setopt($curl, CURLOPT_MAXREDIRS, $this->getMaxRedirects());
curl_setopt($curl, CURLOPT_FAILONERROR, !$this->getIgnoreErrors());
@@ -15,7 +15,7 @@
*/
public function getStreamContextArray(RequestInterface $request)
{
- return array(
+ $options = array(
'http' => array(
// values from the request
'method' => $request->getMethod(),
@@ -32,5 +32,12 @@ public function getStreamContextArray(RequestInterface $request)
'verify_peer' => $this->getVerifyPeer(),
),
);
+
+ if ($this->proxy) {
+ $options['http']['proxy'] = $this->proxy;
+ $options['http']['request_fulluri'] = true;
+ }
+
+ return $options;
}
}
View
@@ -9,6 +9,7 @@
<php>
<!-- <server name="TEST_SERVER" value="http://localhost/buzz/test/server.php" /> -->
+ <!-- <server name="TEST_PROXY" value="localhost:3128" /> -->
</php>
<filter>
@@ -177,6 +177,25 @@ public function testRedirectedResponse($client)
}
/**
+ * @dataProvider provideClient
+ */
+ public function testProxy($client)
+ {
+ if (!isset($_SERVER['TEST_PROXY'])) {
+ $this->markTestSkipped('The proxy server is not configured.');
+ }
+
+ $client->setProxy($_SERVER['TEST_PROXY']);
+
+ $request = new Request();
+ $request->fromUrl($_SERVER['TEST_SERVER']);
+ $response = $this->send($client, $request);
+
+ $data = json_decode($response->getContent(), true);
+ $this->assertArrayHasKey('HTTP_VIA', $data['SERVER']);
+ }
+
+ /**
* @expectedException RuntimeException
* @expectedExceptionMessage Protocol pop3 not supported or disabled in libcurl
*/
View
@@ -0,0 +1,2 @@
+http_access allow all
+http_port 3128

0 comments on commit 98b850f

Please sign in to comment.