From e8f8d1839e6dd7e6d26956e1d9e1c8ef532f1c35 Mon Sep 17 00:00:00 2001 From: Marcus Bointon Date: Tue, 29 Sep 2020 11:37:04 +0200 Subject: [PATCH 01/10] See if it will run on newer platforms --- .travis.yml | 6 +++--- composer.json | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 1c5e371..abe0ff0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,13 +1,13 @@ language: php php: - - 7.1 - - 7.2 - 7.3 + - 7.4 + - 8.0 sudo: false -dist: trusty +dist: focal before_script: - composer self-update diff --git a/composer.json b/composer.json index d1c56b9..a3f1851 100644 --- a/composer.json +++ b/composer.json @@ -16,9 +16,9 @@ } ], "require": { - "php": "^5.6 || ^7.0", + "php": "^7.0||^8.0", "psr/http-message": "^1.0", - "guzzlehttp/guzzle": "^6.0", + "guzzlehttp/guzzle": "^6.0||^7.1", "laminas/laminas-diactoros": "^2.0", "relay/relay": "^1.0", "laminas/laminas-httphandlerrunner": "^1.1" From d8e23c5a7c251448277fe8c8e1844ac01dfff982 Mon Sep 17 00:00:00 2001 From: Marcus Bointon Date: Tue, 29 Sep 2020 11:42:53 +0200 Subject: [PATCH 02/10] Trigger travis build --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index f29a549..00c1c61 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,7 @@ This is a HTTP/HTTPS proxy script that forwards requests to a different server and returns the response. The Proxy class uses PSR7 request/response objects as input/output, and uses Guzzle to do the actual HTTP request. +x ## Installation Install using composer: From 2e499714badbc654478d4956d117e123abf25f44 Mon Sep 17 00:00:00 2001 From: Marcus Bointon Date: Tue, 29 Sep 2020 11:49:37 +0200 Subject: [PATCH 03/10] Focal doesn't have 7.3, so downgrade to bionic PHP 8.0 needs to be nightly for now --- .travis.yml | 4 ++-- README.md | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index abe0ff0..f7e3358 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,11 +3,11 @@ language: php php: - 7.3 - 7.4 - - 8.0 + - nightly sudo: false -dist: focal +dist: bionic before_script: - composer self-update diff --git a/README.md b/README.md index 00c1c61..95cfba7 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ This is a HTTP/HTTPS proxy script that forwards requests to a different server and returns the response. The Proxy class uses PSR7 request/response objects as input/output, and uses Guzzle to do the actual HTTP request. -x + ## Installation Install using composer: From 808f55d787415a46944c9b78a79bcb481b7a1154 Mon Sep 17 00:00:00 2001 From: Marcus Bointon Date: Tue, 29 Sep 2020 14:06:24 +0200 Subject: [PATCH 04/10] Disable PHP 8 - Laminas incompatible --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index f7e3358..3f1d11c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,6 @@ language: php php: - 7.3 - 7.4 - - nightly sudo: false From dd264a16a6e25201d4419b8c08c8f8b5ebc70106 Mon Sep 17 00:00:00 2001 From: Marcus Bointon Date: Tue, 29 Sep 2020 14:06:57 +0200 Subject: [PATCH 05/10] Fix PHPUnit 9 compatibility issues --- tests/Proxy/Adapter/Dummy/DummyAdapterTest.php | 2 +- tests/Proxy/Adapter/Guzzle/GuzzleAdapterTest.php | 2 +- tests/Proxy/Filter/RemoveEncodingFilterTest.php | 2 +- tests/Proxy/Filter/RemoveLocationFilterTest.php | 2 +- tests/Proxy/Filter/RewriteLocationFilterTest.php | 2 +- tests/Proxy/ProxyTest.php | 4 ++-- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/Proxy/Adapter/Dummy/DummyAdapterTest.php b/tests/Proxy/Adapter/Dummy/DummyAdapterTest.php index 62a869b..a4a52cc 100644 --- a/tests/Proxy/Adapter/Dummy/DummyAdapterTest.php +++ b/tests/Proxy/Adapter/Dummy/DummyAdapterTest.php @@ -13,7 +13,7 @@ class DummyAdapterTest extends TestCase */ private $adapter; - public function setUp() + public function setUp(): void { $this->adapter = new DummyAdapter(); } diff --git a/tests/Proxy/Adapter/Guzzle/GuzzleAdapterTest.php b/tests/Proxy/Adapter/Guzzle/GuzzleAdapterTest.php index 9f9940b..0bdc338 100644 --- a/tests/Proxy/Adapter/Guzzle/GuzzleAdapterTest.php +++ b/tests/Proxy/Adapter/Guzzle/GuzzleAdapterTest.php @@ -32,7 +32,7 @@ class GuzzleAdapterTest extends TestCase */ private $body = 'Totally awesome response body'; - public function setUp() + public function setUp(): void { $mock = new MockHandler([ $this->createResponse(), diff --git a/tests/Proxy/Filter/RemoveEncodingFilterTest.php b/tests/Proxy/Filter/RemoveEncodingFilterTest.php index c407695..7a397ca 100644 --- a/tests/Proxy/Filter/RemoveEncodingFilterTest.php +++ b/tests/Proxy/Filter/RemoveEncodingFilterTest.php @@ -13,7 +13,7 @@ class RemoveEncodingFilterTest extends TestCase */ private $filter; - public function setUp() + public function setUp(): void { $this->filter = new RemoveEncodingFilter(); } diff --git a/tests/Proxy/Filter/RemoveLocationFilterTest.php b/tests/Proxy/Filter/RemoveLocationFilterTest.php index ea96bde..a9a4971 100644 --- a/tests/Proxy/Filter/RemoveLocationFilterTest.php +++ b/tests/Proxy/Filter/RemoveLocationFilterTest.php @@ -13,7 +13,7 @@ class RemoveLocationFilterTest extends TestCase */ private $filter; - public function setUp() + public function setUp(): void { $this->filter = new RemoveLocationFilter(); } diff --git a/tests/Proxy/Filter/RewriteLocationFilterTest.php b/tests/Proxy/Filter/RewriteLocationFilterTest.php index 3bcc5f4..c67b71e 100644 --- a/tests/Proxy/Filter/RewriteLocationFilterTest.php +++ b/tests/Proxy/Filter/RewriteLocationFilterTest.php @@ -11,7 +11,7 @@ class RewriteLocationFilterTest extends TestCase */ private $filter; - public function setUp() + public function setUp(): void { $this->filter = new RewriteLocationFilter(); } diff --git a/tests/Proxy/ProxyTest.php b/tests/Proxy/ProxyTest.php index b46017e..37f4359 100644 --- a/tests/Proxy/ProxyTest.php +++ b/tests/Proxy/ProxyTest.php @@ -17,17 +17,17 @@ class ProxyTest extends TestCase */ private $proxy; - public function setUp() + public function setUp(): void { $this->proxy = new Proxy(new DummyAdapter()); } /** * @test - * @expectedException UnexpectedValueException */ public function to_throws_exception_if_no_request_is_given() { + $this->expectException('UnexpectedValueException'); $this->proxy->to('http://www.example.com'); } From 85cb41fd02d999186ec7fbbf93402d8b9702e7ad Mon Sep 17 00:00:00 2001 From: Marcus Bointon Date: Tue, 29 Sep 2020 14:07:43 +0200 Subject: [PATCH 06/10] Update deps, inc PHP and Guzzle --- composer.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/composer.json b/composer.json index a3f1851..6451915 100644 --- a/composer.json +++ b/composer.json @@ -16,15 +16,15 @@ } ], "require": { - "php": "^7.0||^8.0", + "php": "^7.3", "psr/http-message": "^1.0", - "guzzlehttp/guzzle": "^6.0||^7.1", - "laminas/laminas-diactoros": "^2.0", + "guzzlehttp/guzzle": "^7.1", + "laminas/laminas-diactoros": "^2.4", "relay/relay": "^1.0", - "laminas/laminas-httphandlerrunner": "^1.1" + "laminas/laminas-httphandlerrunner": "^1.2" }, "require-dev": { - "phpunit/phpunit": "^5.0|^6.0|^7.0", + "phpunit/phpunit": "^9.0", "php-coveralls/php-coveralls": "^2.0", "mockery/mockery": "^1.1" }, From 14dadfc9c119af3a730d31b76fc38f881a3048b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Viktor=20Breitenb=C3=BCcher?= Date: Fri, 6 Nov 2020 14:34:57 +0700 Subject: [PATCH 07/10] Return 4xx Responses. --- src/Proxy.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Proxy.php b/src/Proxy.php index 630501f..42d4bfb 100644 --- a/src/Proxy.php +++ b/src/Proxy.php @@ -2,6 +2,7 @@ namespace Proxy; +use GuzzleHttp\Exception\ClientException; use Proxy\Adapter\AdapterInterface; use Proxy\Exception\UnexpectedValueException; use Psr\Http\Message\RequestInterface; @@ -79,7 +80,11 @@ public function to($target) $stack = $this->filters; $stack[] = function (RequestInterface $request, ResponseInterface $response, callable $next) { - $response = $this->adapter->send($request); + try { + $response = $this->adapter->send($request); + } catch (ClientException $ex) { + $response = $ex->getResponse(); + } return $next($request, $response); }; From df8e0dc713cd565068aba88eeae11e84c6701a0c Mon Sep 17 00:00:00 2001 From: Alexander Bogdanov Date: Wed, 16 Dec 2020 15:19:16 +0300 Subject: [PATCH 08/10] added example block to handle bad responses --- README.md | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 95cfba7..81238df 100644 --- a/README.md +++ b/README.md @@ -35,11 +35,16 @@ $proxy = new Proxy(new GuzzleAdapter($guzzle)); // Add a response filter that removes the encoding headers. $proxy->filter(new RemoveEncodingFilter()); -// Forward the request and get the response. -$response = $proxy->forward($request)->to('http://example.com'); - -// Output response to the browser. -(new Laminas\HttpHandlerRunner\Emitter\SapiEmitter)->emit($response); +try { + // Forward the request and get the response. + $response = $proxy->forward($request)->to('http://example.com'); + + // Output response to the browser. + (new Laminas\HttpHandlerRunner\Emitter\SapiEmitter)->emit($response); +} catch(\GuzzleHttp\Exception\BadResponseException $e) { + // Correct way to handle bad responses + (new Laminas\HttpHandlerRunner\Emitter\SapiEmitter)->emit($e->getResponse()); +} ``` ## Filters From 25c86f9e2e551ad6d4fd6bad40a4224a980fff67 Mon Sep 17 00:00:00 2001 From: Marcus Bointon Date: Sat, 16 Oct 2021 12:57:58 +0200 Subject: [PATCH 09/10] Update diactoros and enable PHP 8.0 --- composer.json | 4 ++-- phpunit.xml | 41 +++++++++++++++++++++-------------------- 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/composer.json b/composer.json index 6451915..b36f377 100644 --- a/composer.json +++ b/composer.json @@ -16,10 +16,10 @@ } ], "require": { - "php": "^7.3", + "php": "^7.3 || ^8.0", "psr/http-message": "^1.0", "guzzlehttp/guzzle": "^7.1", - "laminas/laminas-diactoros": "^2.4", + "laminas/laminas-diactoros": "^2.5", "relay/relay": "^1.0", "laminas/laminas-httphandlerrunner": "^1.2" }, diff --git a/phpunit.xml b/phpunit.xml index 8034fdf..eb45487 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,22 +1,23 @@ - - - - tests/Proxy/ - - - - - ./src - - + + + + ./src + + + + + tests/Proxy/ + + From a2ebcfa894d4b359cbda6f639e1441ab93a107a8 Mon Sep 17 00:00:00 2001 From: Marcus Bointon Date: Sat, 16 Oct 2021 12:58:38 +0200 Subject: [PATCH 10/10] Add roave/security-advisories Bump dev package versions, including PHPUnit --- composer.json | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index b36f377..39e983a 100644 --- a/composer.json +++ b/composer.json @@ -24,9 +24,10 @@ "laminas/laminas-httphandlerrunner": "^1.2" }, "require-dev": { - "phpunit/phpunit": "^9.0", - "php-coveralls/php-coveralls": "^2.0", - "mockery/mockery": "^1.1" + "roave/security-advisories": "dev-latest", + "phpunit/phpunit": "^9.5", + "php-coveralls/php-coveralls": "^2.4", + "mockery/mockery": "^1.4" }, "autoload": { "psr-4": {