From d3892d73af078012472db7cf81a4cba4015d36b4 Mon Sep 17 00:00:00 2001 From: Marius Gavrilescu Date: Sat, 13 Dec 2014 18:30:39 +0200 Subject: [PATCH] Use ?format=json instead of Accept: application/json --- js/90-tracker.js | 3 +-- lib/Plack/App/Gruntmaster.pm | 5 +++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/js/90-tracker.js b/js/90-tracker.js index a475ee8..8e7a443 100644 --- a/js/90-tracker.js +++ b/js/90-tracker.js @@ -77,8 +77,7 @@ $('#tracker_form').addClass('hidden'); update_tracker(); var xhr = new XMLHttpRequest(); - xhr.open('GET', '/us/' + user); - xhr.setRequestHeader('Accept', 'application/json'); + xhr.open('GET', '/us/' + user + '?format=json'); xhr.onload = function () { localStorage.setItem('tracker_data', this.responseText); update_tracker(); diff --git a/lib/Plack/App/Gruntmaster.pm b/lib/Plack/App/Gruntmaster.pm index b84dc81..af1eb78 100644 --- a/lib/Plack/App/Gruntmaster.pm +++ b/lib/Plack/App/Gruntmaster.pm @@ -125,11 +125,12 @@ sub dispatch_request{ response_filter { return shift } }, - sub () { + sub (?:format~) { + my $format = lc $_{format} // ''; response_filter { my ($r) = @_; return $r if ref $r ne 'Plack::App::Gruntmaster::Response'; - return [200, ['Content-Type' => 'application/json', 'X-Forever' => 1], [encode_json $r->{params}]] if $env->{HTTP_ACCEPT} =~ m,^\s*application/json\s*$,g; + return [200, ['Content-Type' => 'application/json', 'X-Forever' => 1], [encode_json $r->{params}]] if $format eq 'json'; my $ret = render $r->{template}, 'en', title => $r->{title}, %{$r->{params}}; [200, ['Content-Type' => 'text/html'], [encode 'UTF-8', $ret]] }, -- 2.39.2