Skip to content

Commit 2f4f8c0

Browse files
committed
bug #31982 [HttpClient] fix Psr18Client handling of non-200 response codes (nicolas-grekas)
This PR was merged into the 4.3 branch. Discussion ---------- [HttpClient] fix Psr18Client handling of non-200 response codes | Q | A | ------------- | --- | Branch? | 4.3 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #31979 | License | MIT | Doc PR | - Commits ------- 4a79894 [HttpClient] fix Psr18Client handling of non-200 response codes
2 parents cf728f5 + 4a79894 commit 2f4f8c0

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->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)