[HttpFoundation] fix not sending Content-Type header for 204 responses

This commit is contained in:
Tobias Schultze 2020-02-13 19:35:54 +01:00
parent e87b59971e
commit 06f5a1113d
2 changed files with 5 additions and 11 deletions

View File

@ -267,10 +267,12 @@ class Response
$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);
}

View File

@ -461,18 +461,10 @@ class ResponseTest extends ResponseTestCase
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()