From ed88bbaac031679039991a57a055d1cd53432803 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 25 Mar 2016 14:48:12 +0100 Subject: [PATCH] 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. --- src/lib/Hydra/Controller/Root.pm | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/lib/Hydra/Controller/Root.pm b/src/lib/Hydra/Controller/Root.pm index 728f10ba..8aa26864 100644 --- a/src/lib/Hydra/Controller/Root.pm +++ b/src/lib/Hydra/Controller/Root.pm @@ -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'); }