Set Vary to Accept

Otherwise, the browser may mix up HTML and JSON responses if it has
requested both. For example, hitting the back button to return to a
job metric page will show a JSON response, because that was the last
thing the browser fetched for that URL.

This requires Catalyst::Action::Rest >= 1.20.
This commit is contained in:
Eelco Dolstra 2016-03-25 14:48:12 +01:00
parent 32adc53070
commit ed88bbaac0

View file

@ -67,6 +67,10 @@ sub begin :Private {
unless (defined $c->stash->{params} and %{$c->stash->{params}}) {
$c->stash->{params} = $c->request->params;
}
# Set the Vary header to "Accept" to ensure that browsers don't
# mix up HTML and JSON responses.
$c->response->headers->header('Vary', 'Accept');
}