Skip to content

Commit 1c6db72

Browse files
Merge branch '4.4' into 5.4
* 4.4: [Bridge] Fix mkdir() race condition in ProxyCacheWarmer [Cache] update readme Psr18Client ignore invalid HTTP headers skip a transient test on AppVeyor
2 parents 6a057be + 0952740 commit 1c6db72

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

Psr18Client.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,11 @@ public function sendRequest(RequestInterface $request): ResponseInterface
101101

102102
foreach ($response->getHeaders(false) as $name => $values) {
103103
foreach ($values as $value) {
104-
$psrResponse = $psrResponse->withAddedHeader($name, $value);
104+
try {
105+
$psrResponse = $psrResponse->withAddedHeader($name, $value);
106+
} catch (\InvalidArgumentException $e) {
107+
// ignore invalid header
108+
}
105109
}
106110
}
107111

Tests/Psr18ClientTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@
1313

1414
use Nyholm\Psr7\Factory\Psr17Factory;
1515
use PHPUnit\Framework\TestCase;
16+
use Symfony\Component\HttpClient\MockHttpClient;
1617
use Symfony\Component\HttpClient\NativeHttpClient;
1718
use Symfony\Component\HttpClient\Psr18Client;
1819
use Symfony\Component\HttpClient\Psr18NetworkException;
1920
use Symfony\Component\HttpClient\Psr18RequestException;
21+
use Symfony\Component\HttpClient\Response\MockResponse;
2022
use Symfony\Contracts\HttpClient\Test\TestHttpServer;
2123

2224
class Psr18ClientTest extends TestCase
@@ -81,4 +83,22 @@ public function test404()
8183
$response = $client->sendRequest($factory->createRequest('GET', 'http://localhost:8057/404'));
8284
$this->assertSame(404, $response->getStatusCode());
8385
}
86+
87+
public function testInvalidHeaderResponse()
88+
{
89+
$responseHeaders = [
90+
// space in header name not allowed in RFC 7230
91+
' X-XSS-Protection' => '0',
92+
'Cache-Control' => 'no-cache',
93+
];
94+
$response = new MockResponse('body', ['response_headers' => $responseHeaders]);
95+
$this->assertArrayHasKey(' x-xss-protection', $response->getHeaders());
96+
97+
$client = new Psr18Client(new MockHttpClient($response));
98+
$request = $client->createRequest('POST', 'http://localhost:8057/post')
99+
->withBody($client->createStream('foo=0123456789'));
100+
101+
$resultResponse = $client->sendRequest($request);
102+
$this->assertCount(1, $resultResponse->getHeaders());
103+
}
84104
}

0 commit comments

Comments
 (0)