8000 [HttpFoundation] fix not sending Content-Type header for 204 responses · symfony/symfony@06f5a11 · GitHub
[go: up one dir, main page]

Skip to content

Commit 06f5a11

Browse files
committed
[HttpFoundation] fix not sending Content-Type header for 204 responses
1 parent e87b599 commit 06f5a11

File tree

2 files changed

+5
-11
lines changed

2 files changed

+5
-11
lines changed

src/Symfony/Component/HttpFoundation/Response.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,10 +267,12 @@ public function prepare(Request $request)
267267
$this->setContent(null);
268268
$headers->remove('Content-Type');
269269
$headers->remove('Content-Length');
270+
// prevent PHP from sending the Content-Type header based on default_mimetype
271+
ini_set('default_mimetype', '');
270272
} else {
271273
// Content-type based on the Request
272274
if (!$headers->has('Content-Type')) {
273-
$format = $request->getPreferredFormat();
275+
$format = $request->getPreferredFormat(null);
274276
if (null !== $format && $mimeType = $request->getMimeType($format)) {
275277
$headers->set('Content-Type', $mimeType);
276278
}

src/Symfony/Component/HttpFoundation/Tests/ResponseTest.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -461,18 +461,10 @@ public function testSetVary()
461461

462462
public function testDefaultContentType()
463463
{
464-
$headerMock = $this->getMockBuilder('Symfony\Component\HttpFoundation\ResponseHeaderBag')->setMethods(['set'])->getMock();
465-
$headerMock->expects($this->at(0))
466-
->method('set')
467-
->with('Content-Type', 'text/html');
468-
$headerMock->expects($this->at(1))
469-
->method('set')
470-
->with('Content-Type', 'text/html; charset=UTF-8');
471-
472464
$response = new Response('foo');
473-
$response->headers = $headerMock;
474-
475465
$response->prepare(new Request());
466+
467+
$this->assertSame('text/html; charset=UTF-8', $response->headers->get('Content-Type'));
476468
}
477469

478470
public function testContentTypeCharset()

0 commit comments

Comments
 (0)
0