Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2f4f8c0

Browse filesBrowse 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
Copy full SHA for 2f4f8c0

File tree

2 files changed

+11
-2
lines changed
Filter options

2 files changed

+11
-2
lines changed

‎src/Symfony/Component/HttpClient/Psr18Client.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpClient/Psr18Client.php
+2-2Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpClient/Tests/Psr18ClientTest.php
+9Lines 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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.