[HttpClient] fix Psr18Client handling of non-200 response codes

This commit is contained in:
Nicolas Grekas 2019-06-10 19:33:26 +02:00
parent 2b8e44164e
commit 4a7989456b
2 changed files with 11 additions and 2 deletions

View File

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

View File

@ -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());
}
}