Skip Menu |

This queue is for tickets about the HTTP-Body CPAN distribution.

Report information
The Basics
Id: 79363
Status: new
Priority: 0/
Queue: HTTP-Body

Owner: Nobody in particular
Requestors: gbjk [...]

Bug Information
Severity: Important
Broken in: 1.15
Fixed in: (no value)

Subject: application/json parsed as XForms:Model
Download (untitled) / with headers
text/plain 741b
If a client posts application/json content type (as submitted by ExtJS, jquery, etc) then HTTP::Body parses it as XForms:Model, because the content-type is "application/json, application/xml" (for better or worse). This adds a $req->param XForms:Model, which needs to be ignored in web apps. Instead, I propose that the application/json type is parsed as an octet stream, leaving params alone, and purely available in data. This doesn't break anything I've seen so far. I've also made it so that if a content-type is submitted with multiple types (again, possibly incorrectly, but we live with what's out there), then we'll consistently take the first matching occurrence, rather than leaving it to chance. Patch attached. gbjk
Subject: HTTP-Body-1.15.patch
diff -Naur HTTP-Body-1.15.orig/lib/HTTP/ HTTP-Body-1.15/lib/HTTP/ --- HTTP-Body-1.15.orig/lib/HTTP/ 2012-08-30 16:58:58.999387392 +0100 +++ HTTP-Body-1.15/lib/HTTP/ 2012-08-30 17:18:32.932039128 +0100 @@ -12,7 +12,8 @@ 'application/x-www-form-urlencoded' => 'HTTP::Body::UrlEncoded', 'multipart/form-data' => 'HTTP::Body::MultiPart', 'multipart/related' => 'HTTP::Body::XFormsMultipart', - 'application/xml' => 'HTTP::Body::XForms' + 'application/xml' => 'HTTP::Body::XForms', + 'application/json' => 'HTTP::Body::OctetStream', }; require HTTP::Body::OctetStream; @@ -58,9 +59,9 @@ =head1 DESCRIPTION -HTTP::Body parses chunks of HTTP POST data and supports -application/octet-stream, application/x-www-form-urlencoded, and -multipart/form-data. +HTTP::Body parses chunks of HTTP POST data and supports +application/octet-stream, application/json, application/x-www-form-urlencoded, +and multipart/form-data. Chunked bodies are supported by not passing a length value to new(). @@ -92,9 +93,12 @@ } my $type; + my $earliest_index; foreach my $supported ( keys %{$TYPES} ) { - if ( index( lc($content_type), $supported ) >= 0 ) { - $type = $supported; + my $index = index( lc($content_type), $supported ); + if ($index >= 0 && (!defined $earliest_index || $index < $earliest_index)) { + $type = $supported; + $earliest_index = $index; } }

This service is sponsored and maintained by Best Practical Solutions and runs on infrastructure.

Please report any issues with to