From 83a16ac114bb0f3f021742d1c5f1b90b27836030 Mon Sep 17 00:00:00 2001 From: Philipp Date: Tue, 12 Jul 2022 19:49:39 +0200 Subject: [PATCH 1/2] Add test case for https://github.com/friendica/friendica/issues/11726 --- .../Network/HTTPClient/Client/HTTPClientTest.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/src/Network/HTTPClient/Client/HTTPClientTest.php b/tests/src/Network/HTTPClient/Client/HTTPClientTest.php index a6a873c83..cbe2a8436 100644 --- a/tests/src/Network/HTTPClient/Client/HTTPClientTest.php +++ b/tests/src/Network/HTTPClient/Client/HTTPClientTest.php @@ -49,4 +49,19 @@ class HTTPClientTest extends MockedTest self::assertFalse(DI::httpClient()->get('https://friendica.local')->isSuccess()); } + + /** + * Test for issue https://github.com/friendica/friendica/issues/11726 + */ + public function testRedirect() + { + $this->httpRequestHandler->setHandler(new MockHandler([ + new Response(302, ['Location' => 'https://mastodon.social/about']), + new Response(200, ['Location' => 'https://mastodon.social']), + ])); + + $result = DI::httpClient()->get('https://mastodon.social'); + self::assertEquals('https://mastodon.social', $result->getUrl()); + self::assertEquals('https://mastodon.social/about', $result->getRedirectUrl()); + } } From 8e547510a0ccd4f7b44e0dd335ae9e950b5d8ba1 Mon Sep 17 00:00:00 2001 From: Philipp Date: Tue, 12 Jul 2022 20:09:18 +0200 Subject: [PATCH 2/2] Fix HTTP Client redirect Bug --- src/Network/HTTPClient/Factory/HttpClient.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Network/HTTPClient/Factory/HttpClient.php b/src/Network/HTTPClient/Factory/HttpClient.php index b3fd76936..29ef3c09e 100644 --- a/src/Network/HTTPClient/Factory/HttpClient.php +++ b/src/Network/HTTPClient/Factory/HttpClient.php @@ -94,11 +94,11 @@ class HttpClient extends BaseFactory $guzzle = new GuzzleHttp\Client([ RequestOptions::ALLOW_REDIRECTS => [ - 'max' => 8, - 'on_redirect' => $onRedirect, - 'track_redirect' => true, - 'strict' => true, - 'referer' => true, + 'max' => 8, + 'on_redirect' => $onRedirect, + 'track_redirects' => true, + 'strict' => true, + 'referer' => true, ], RequestOptions::HTTP_ERRORS => false, // Without this setting it seems as if some webservers send compressed content