8000 [HttpClient] fix Psr18Client handling of non-200 response codes · symfony/symfony@4a79894 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4a79894

Browse files
[HttpClient] fix Psr18Client handling of non-200 response codes
1 parent 2b8e441 commit 4a79894

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/Symfony/Component/HttpClient/Psr18Client.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,13 @@ public function sendRequest(RequestInterface $request): ResponseInterface
7373

7474
$psrResponse = $this->responseFactory->createResponse($response->getStatusCode());
7575

76-
foreach ($response->getHeaders() as $name => $values) {
76+
foreach ($response->getHeaders(false) as $name => $values) {
7777
foreach ($values as $value) {
7878
$psrResponse = $psrResponse->withAddedHeader($name, $value);
7979
}
8080
}
8181

82-
return $psrResponse->withBody($this->streamFactory->createStream($response-& 8000 gt;getContent()));
82+
return $psrResponse->withBody($this->streamFactory->createStream($response->getContent(false)));
8383
} catch (TransportExceptionInterface $e) {
8484
if ($e instanceof \InvalidArgumentException) {
8585
throw new Psr18RequestException($e, $request);

src/Symfony/Component/HttpClient/Tests/Psr18ClientTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,13 @@ public function testRequestException()
7474
$this->expectException(Psr18RequestException::class);
7575
$client->sendRequest($factory->createRequest('BAD.METHOD', 'http://localhost:8057'));
7676
}
77+
78+
public function test404()
79+
{
80+
$factory = new Psr17Factory();
81+
$client = new Psr18Client(new NativeHttpClient());
82+
83+
$response = $client->sendRequest($factory->createRequest('GET', 'http://localhost:8057/404'));
84+
$this->assertSame(404, $response->getStatusCode());
85+
}
7786
}

0 commit comments

Comments
 (0)
0