From d4a0732752e79b57509cee33001ab757132366c5 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Wed, 15 Jun 2011 20:02:14 -0400 Subject: let thru HTTP_ACCEPT Needed for attachment to return json when requested. I think some browsers send Accept: * , so I made sure to check that json was explicitly listed as to be accepted, as well as having a high priority. --- IkiWiki/Plugin/attachment.pm | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) (limited to 'IkiWiki/Plugin') diff --git a/IkiWiki/Plugin/attachment.pm b/IkiWiki/Plugin/attachment.pm index 6004a0982..4af9ac92b 100644 --- a/IkiWiki/Plugin/attachment.pm +++ b/IkiWiki/Plugin/attachment.pm @@ -252,22 +252,25 @@ sub attachment_store { IkiWiki::fast_file_copy($tempfile, $filename, $fh, @_); }); } - + # Return JSON response for the jquery file upload widget. - eval q{use JSON}; - error $@ if $@; - print "Content-type: application/json\n\n"; - my $size=-s $dest."/".$filename; - print to_json([ - { - name => $filename, - size => $size, - humansize => IkiWiki::Plugin::filecheck::humansize($size), - stored_msg => stored_msg(), - - } - ]); - exit 0; + if ($q->Accept("application/json") >= 1.0 && + grep { /application\/json/i } $q->Accept) { + eval q{use JSON}; + error $@ if $@; + print "Content-type: application/json\n\n"; + my $size=-s $dest."/".$filename; + print to_json([ + { + name => $filename, + size => $size, + humansize => IkiWiki::Plugin::filecheck::humansize($size), + stored_msg => stored_msg(), + + } + ]); + exit 0; + } } # Save all stored attachments for a page. -- cgit v1.2.3