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 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);

This comment has been minimized.

Copy link
@Tobion

Tobion Feb 13, 2020

Author Member

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.

@Tobion Tobion force-pushed the Tobion:no-content-type-on-204 branch from e868336 to 06f5a11 Feb 13, 2020
@fabpot
fabpot approved these changes Feb 14, 2020
@@ -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', '');

This comment has been minimized.

Copy link
@fabpot

fabpot Feb 14, 2020

Member

This should be merged in 3.4 as well, right?

@fabpot

This comment has been minimized.

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
2 of 3 checks passed
2 of 3 checks passed
continuous-integration/travis-ci/pr The Travis CI build failed
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
fabbot.io Your code looks good.
Details
@Tobion Tobion deleted the Tobion:no-content-type-on-204 branch Feb 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.