Skip to content

[TwigBundle] 'Content-Type' response header match the requested format when generating error pages #22548

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

Closed
wants to merge 2 commits into from

Conversation

damienflament
Copy link

@damienflament damienflament commented Apr 27, 2017

Q A
Branch? master
Bug fix? no related issue found
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes/no
Fixed tickets -
License MIT
Doc PR -

The Content-Type response header needs to match the format of the generated response content.

This is obviously useful when an exception is thrown during an XMLHttpRequest handling using JSON content. Currently, the browser (Firefox Developer Edition) handles well the response content and show it as a JSON object. Maybe by looking the request content type or just by recognizing the response content type while parsing it. But the response type is shown as html. This PR fix it.

By using the Request::getMimeType() method, we take care of the additional format added by the developer.

…t when generating error pages.

The 'Content-Type' response header need to match the format of the generated response content.

This is obviously useful when an exception is thrown during an XMLHttpRequest handling using JSON content. Currently, the browser (Firefox Developer Edition) handles well the response content and show it as a JSON object. Maybe by looking the request content type or just by recognizing the response content type while parsing it. But the response type is shown as _html_. This PR fix it.

By using the _Request::getMimeType()_ method, we take care of the additional format added by the developer.
@damienflament
Copy link
Author

There is a test failure because I pass the exception status code to the created Response object instead of the default 200 HTTP status code. But returning a 200 HTTP status code seems unsuitable when showing an error.

@nicolas-grekas nicolas-grekas changed the title [TwigBundle] 'Content-Type' response header match the requested forma… [TwigBundle] 'Content-Type' response header match the requested format when generating error pages Apr 27, 2017
@xabbuh xabbuh added this to the 2.7 milestone May 20, 2017
@fabpot
Copy link
Member

fabpot commented Jul 6, 2017

@damienflament Can you rebase this pull request?

@nicolas-grekas
Copy link
Member

Fixed in #23052

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.

5 participants