Skip to content

Commit 6d45aef

Browse files
minor #38819 [HttpKernel] HttpKernelBrowser: don't set a default Accept header (dunglas)
This PR was squashed before being merged into the 5.x branch. Discussion ---------- [HttpKernel] HttpKernelBrowser: don't set a default Accept header | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | Fix #33393 | License | MIT | Doc PR | n/a Currently, the `Accept` HTTP header is set automatically, because there is a default value for this value in HttpFoundation's `Request::create()` method. This PR remove the default value if it hasn't been set automatically. This will fix API Platform's `ApiTestCase` and `Behatch/contexts` (the previous workarounds aren't applicable anymore because we added type checks in Symfony). Commits ------- bf13887898 [HttpKernel] HttpKernelBrowser: don't set a default Accept header
2 parents 288ad47 + 732885d commit 6d45aef

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ CHANGELOG
1313
* Allowed adding attributes on controller arguments that will be passed to argument resolvers.
1414
* kernels implementing the `ExtensionInterface` will now be auto-registered to the container
1515
* added parameter `kernel.runtime_environment`, defined as `%env(default:kernel.environment:APP_RUNTIME_ENV)%`
16+
* do not set a default `Accept` HTTP header when using `HttpKernelBrowser`
1617

1718
5.1.0
1819
-----

HttpKernelBrowser.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,10 @@ protected function getHandleScript()
130130
*/
131131
protected function filterRequest(DomRequest $request)
132132
{
133-
$httpRequest = Request::create($request->getUri(), $request->getMethod(), $request->getParameters(), $request->getCookies(), $request->getFiles(), $request->getServer(), $request->getContent());
133+
$httpRequest = Request::create($request->getUri(), $request->getMethod(), $request->getParameters(), $request->getCookies(), $request->getFiles(), $server = $request->getServer(), $request->getContent());
134+
if (!isset($server['HTTP_ACCEPT'])) {
135+
$httpRequest->headers->remove('Accept');
136+
}
134137

135138
foreach ($this->filterFiles($httpRequest->files->all()) as $key => $value) {
136139
$httpRequest->files->set($key, $value);

Tests/HttpKernelBrowserTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,4 +179,15 @@ public function testUploadedFileWhenSizeExceedsUploadMaxFileSize()
179179

180180
unlink($source);
181181
}
182+
183+
public function testAcceptHeaderNotSet()
184+
{
185+
$client = new HttpKernelBrowser(new TestHttpKernel());
186+
187+
$client->request('GET', '/');
188+
$this->assertFalse($client->getRequest()->headers->has('Accept'));
189+
190+
$client->request('GET', '/', [], [], ['HTTP_ACCEPT' => 'application/ld+json']);
191+
$this->assertSame('application/ld+json', $client->getRequest()->headers->get('Accept'));
192+
}
182193
}

0 commit comments

Comments
 (0)