Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from Feb 14, 2020

Conversation

Tobion
Copy link
Member

@Tobion Tobion commented Feb 13, 2020

Q A
Branch? 4.4
Bug fix? yes
New feature? no
Deprecations? no
Tickets
License MIT
Doc PR

$headers->remove('Content-Type') did not actually work because PHP sends the Content-Type header based on the https://www.php.net/manual/en/ini.core.php#ini.default-mimetype ini setting anyway (which defaults to html). So we need to disable this ini for empty responses.

} else {
// Content-type based on the Request
if (!$headers->has('Content-Type')) {
$format = $request->getPreferredFormat();
$format = $request->getPreferredFormat(null);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Content-Type gets set to html anyway a few lines below (284). So we don't to ask for the html default here. Otherwise line 284 is basically unreachable.

@@ -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', '');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be merged in 3.4 as well, right?

@fabpot
Copy link
Member

fabpot commented Feb 14, 2020

Thank you @Tobion.

fabpot added a commit that referenced this pull request Feb 14, 2020
…04 responses (Tobion)

This PR was merged into the 4.4 branch.

Discussion
----------

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

| Q             | A
| ------------- | ---
| Branch?       | 4.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       |
| License       | MIT
| Doc PR        |

`$headers->remove('Content-Type')` did not actually work because PHP sends the Content-Type header based on the https://www.php.net/manual/en/ini.core.php#ini.default-mimetype ini setting anyway (which defaults to html). So we need to disable this ini for empty responses.

Commits
-------

06f5a11 [HttpFoundation] fix not sending Content-Type header for 204 responses
@fabpot fabpot merged commit 06f5a11 into symfony:4.4 Feb 14, 2020
@Tobion Tobion deleted the no-content-type-on-204 branch February 14, 2020 13:27
This was referenced Feb 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants