From: Marius Gavrilescu Date: Sat, 13 Dec 2014 16:30:39 +0000 (+0200) Subject: Use ?format=json instead of Accept: application/json X-Git-Url: http://git.ieval.ro/?a=commitdiff_plain;h=d3892d73af078012472db7cf81a4cba4015d36b4;p=plack-app-gruntmaster.git Use ?format=json instead of Accept: application/json --- 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]] },