Skip to content

Commit fd63b94

Browse files
committed
Merge branch '6.2' into 6.3
* 6.2: Remove usage of constant for better consistency across the codebase Remove usage of constant for better consistency across the codebase [HttpClient] Ensure HttplugClient ignores invalid HTTP headers
2 parents 076863d + 32f8e20 commit fd63b94

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

Internal/HttplugWaitLoop.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,11 @@ public function createPsr7Response(ResponseInterface $response, bool $buffer = f
120120

121121
foreach ($response->getHeaders(false) as $name => $values) {
122122
foreach ($values as $value) {
123-
$psrResponse = $psrResponse->withAddedHeader($name, $value);
123+
try {
124+
$psrResponse = $psrResponse->withAddedHeader($name, $value);
125+
} catch (\InvalidArgumentException $e) {
126+
// ignore invalid header
127+
}
124128
}
125129
}
126130

Tests/HttplugClientTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,4 +263,22 @@ function (\Exception $exception) use ($errorMessage, &$failureCallableCalled, $c
263263
$this->assertSame(200, $response->getStatusCode());
264264
$this->assertSame('OK', (string) $response->getBody());
265265
}
266+
267+
public function testInvalidHeaderResponse()
268+
{
269+
$responseHeaders = [
270+
// space in header name not allowed in RFC 7230
271+
' X-XSS-Protection' => '0',
272+
'Cache-Control' => 'no-cache',
273+
];
274+
$response = new MockResponse('body', ['response_headers' => $responseHeaders]);
275+
$this->assertArrayHasKey(' x-xss-protection', $response->getHeaders());
276+
277+
$client = new HttplugClient(new MockHttpClient($response));
278+
$request = $client->createRequest('POST', 'http://localhost:8057/post')
279+
->withBody($client->createStream('foo=0123456789'));
280+
281+
$resultResponse = $client->sendRequest($request);
282+
$this->assertCount(1, $resultResponse->getHeaders());
283+
}
266284
}

0 commit comments

Comments
 (0)