|
13 | 13 |
|
14 | 14 | use Nyholm\Psr7\Factory\Psr17Factory;
|
15 | 15 | use PHPUnit\Framework\TestCase;
|
| 16 | +use Symfony\Component\HttpClient\MockHttpClient; |
16 | 17 | use Symfony\Component\HttpClient\NativeHttpClient;
|
17 | 18 | use Symfony\Component\HttpClient\Psr18Client;
|
18 | 19 | use Symfony\Component\HttpClient\Psr18NetworkException;
|
19 | 20 | use Symfony\Component\HttpClient\Psr18RequestException;
|
| 21 | +use Symfony\Component\HttpClient\Response\MockResponse; |
20 | 22 | use Symfony\Contracts\HttpClient\Test\TestHttpServer;
|
21 | 23 |
|
22 | 24 | class Psr18ClientTest extends TestCase
|
@@ -81,4 +83,22 @@ public function test404()
|
81 | 83 | $response = $client->sendRequest($factory->createRequest('GET', 'http://localhost:8057/404'));
|
82 | 84 | $this->assertSame(404, $response->getStatusCode());
|
83 | 85 | }
|
| 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 | + } |
84 | 104 | }
|
0 commit comments