From: Torsten Raudssus Date: Wed, 3 Oct 2012 15:18:47 +0000 (+0000) Subject: Added patch of gbjk, released 1.16 X-Git-Tag: v1.16^0 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=refs%2Ftags%2Fv1.16;p=catagits%2FHTTP-Body.git Added patch of gbjk, released 1.16 --- diff --git a/dist.ini b/dist.ini index ee2a2e5..1b07698 100644 --- a/dist.ini +++ b/dist.ini @@ -1,5 +1,5 @@ name = HTTP-Body -version = 1.15 +version = 1.16 author = Christian Hansen, C author = Sebastian Riedel, C author = Andy Grundman, C diff --git a/lib/HTTP/Body.pm b/lib/HTTP/Body.pm index acecd21..8a6e22a 100644 --- a/lib/HTTP/Body.pm +++ b/lib/HTTP/Body.pm @@ -9,7 +9,8 @@ our $TYPES = { '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; @@ -55,9 +56,9 @@ HTTP::Body - HTTP Body Parser =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(). @@ -89,9 +90,12 @@ sub new { } 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; } }