From 4a7989456bfd37d3ccb1ff28b2b91290e5e2e18f Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Mon, 10 Jun 2019 19:33:26 +0200 Subject: [PATCH] [HttpClient] fix Psr18Client handling of non-200 response codes --- src/Symfony/Component/HttpClient/Psr18Client.php | 4 ++-- .../Component/HttpClient/Tests/Psr18ClientTest.php | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/HttpClient/Psr18Client.php b/src/Symfony/Component/HttpClient/Psr18Client.php index 17a3d3bd11..a438b7ce94 100644 --- a/src/Symfony/Component/HttpClient/Psr18Client.php +++ b/src/Symfony/Component/HttpClient/Psr18Client.php @@ -73,13 +73,13 @@ final class Psr18Client implements ClientInterface $psrResponse = $this->responseFactory->createResponse($response->getStatusCode()); - foreach ($response->getHeaders() as $name => $values) { + foreach ($response->getHeaders(false) as $name => $values) { foreach ($values as $value) { $psrResponse = $psrResponse->withAddedHeader($name, $value); } } - return $psrResponse->withBody($this->streamFactory->createStream($response->getContent())); + return $psrResponse->withBody($this->streamFactory->createStream($response->getContent(false))); } catch (TransportExceptionInterface $e) { if ($e instanceof \InvalidArgumentException) { throw new Psr18RequestException($e, $request); diff --git a/src/Symfony/Component/HttpClient/Tests/Psr18ClientTest.php b/src/Symfony/Component/HttpClient/Tests/Psr18ClientTest.php index edb2891a37..87b2a7ce0b 100644 --- a/src/Symfony/Component/HttpClient/Tests/Psr18ClientTest.php +++ b/src/Symfony/Component/HttpClient/Tests/Psr18ClientTest.php @@ -74,4 +74,13 @@ class Psr18ClientTest extends TestCase $this->expectException(Psr18RequestException::class); $client->sendRequest($factory->createRequest('BAD.METHOD', 'http://localhost:8057')); } + + public function test404() + { + $factory = new Psr17Factory(); + $client = new Psr18Client(new NativeHttpClient()); + + $response = $client->sendRequest($factory->createRequest('GET', 'http://localhost:8057/404')); + $this->assertSame(404, $response->getStatusCode()); + } }