[HttpFoundation] fix not sending Content-Type header for 204 responses
This commit is contained in:
parent
e87b59971e
commit
06f5a1113d
@ -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);
|
||||
}
|
||||
|
@ -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()
|
||||
|
Reference in New Issue
Block a user