Skip to content

Commit

Permalink
[HttpFoundation] fix not sending Content-Type header for 204 responses
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobion committed Feb 13, 2020
1 parent e87b599 commit 06f5a11
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
4 changes: 3 additions & 1 deletion src/Symfony/Component/HttpFoundation/Response.php
Expand Up @@ -267,10 +267,12 @@ public function prepare(Request $request)
$this->setContent(null);
$headers->remove('Content-Type');
$headers->remove('Content-Length');
// prevent PHP from sending the Content-Type header based on default_mimetype
ini_set('default_mimetype', '');
} else {
// Content-type based on the Request
if (!$headers->has('Content-Type')) {
$format = $request->getPreferredFormat();
$format = $request->getPreferredFormat(null);
if (null !== $format && $mimeType = $request->getMimeType($format)) {
$headers->set('Content-Type', $mimeType);
}
Expand Down
12 changes: 2 additions & 10 deletions src/Symfony/Component/HttpFoundation/Tests/ResponseTest.php
Expand Up @@ -461,18 +461,10 @@ public function testSetVary()

public function testDefaultContentType()
{
$headerMock = $this->getMockBuilder('Symfony\Component\HttpFoundation\ResponseHeaderBag')->setMethods(['set'])->getMock();
$headerMock->expects($this->at(0))
->method('set')
->with('Content-Type', 'text/html');
$headerMock->expects($this->at(1))
->method('set')
->with('Content-Type', 'text/html; charset=UTF-8');

$response = new Response('foo');
$response->headers = $headerMock;

$response->prepare(new Request());

$this->assertSame('text/html; charset=UTF-8', $response->headers->get('Content-Type'));
}

public function testContentTypeCharset()
Expand Down

0 comments on commit 06f5a11

Please sign in to comment.