8000 [TwigBundle] 'Content-Type' response header match the requested format when generating error pages by damienflament · Pull Request #22548 · symfony/symfony · GitHub
[go: up one dir, main page]

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
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
[TwigBundle] 'Content-Type' response header match the requested forma…
…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.
  • Loading branch information
damienflament authored Apr 27, 2017
commit 514edc367c4df58e870f2321f140a6e5fb33e9bc
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,18 @@ public function showAction(Request $request, FlattenException $exception, DebugL
$showException = $request->attributes->get('showException', $this->debug); // As opposed to an additional parameter, this maintains BC

$code = $exception->getStatusCode();
$format = $request->getRequestFormat();

return new Response($this->twig->render(
(string) $this->findTemplate($request, $request->getRequestFormat(), $code, $showException),
(string) $this->findTemplate($request, $format, $code, $showException),
array(
'status_code' => $code,
'status_text' => isset(Response::$statusTexts[$code]) ? Response::$statusTexts[$code] : '',
'exception' => $exception,
'logger' => $logger,
'currentContent' => $currentContent,
)
));
), $code, ['Content-Type' => $request->getMimeType($format)]);
}

/**
Expand Down
0