X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FHTTP%2FBody.pm;h=8a6e22a4b874c28ae62112da814f13b3c11fe648;hb=e4ea94035933e5f86e519b464d62f64ac7544223;hp=eb096b18320b252bffdf5a629ed16d89ca686cbc;hpb=edb3b1f869d6c67ac43dc27b5f3bc98b6028df98;p=catagits%2FHTTP-Body.git diff --git a/lib/HTTP/Body.pm b/lib/HTTP/Body.pm index eb096b1..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; @@ -47,16 +48,17 @@ HTTP::Body - HTTP Body Parser $body->add($buffer); } - my $uploads = $body->upload; # hashref - my $params = $body->param; # hashref - my $body = $body->body; # IO::Handle + my $uploads = $body->upload; # hashref + my $params = $body->param; # hashref + my $param_order = $body->param_order # arrayref + my $body = $body->body; # IO::Handle } =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(). @@ -88,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; } } @@ -106,6 +111,7 @@ sub new { content_type => $content_type, length => 0, param => {}, + param_order => [], state => 'buffering', upload => {}, tmpdir => File::Spec->tmpdir(), @@ -344,6 +350,8 @@ sub param { else { $self->{param}->{$name} = $value; } + + push @{$self->{param_order}}, $name; } return $self->{param}; @@ -388,8 +396,32 @@ sub tmpdir { return $self->{tmpdir}; } +=item param_order + +Returns the array ref of the param keys in the order how they appeared on the body + +=cut + +sub param_order { + return shift->{param_order}; +} + =back +=head1 SUPPORT + +Since its original creation this module has been taken over by the Catalyst +development team. If you want to contribute patches, these will be your +primary contact points: + +IRC: + + Join #catalyst-dev on irc.perl.org. + +Mailing Lists: + + http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst-dev + =head1 AUTHOR Christian Hansen, C @@ -398,6 +430,16 @@ Sebastian Riedel, C Andy Grundman, C +=head1 CONTRIBUTORS + +Simon Elliott C + +Kent Fredric + +Christian Walde + +Torsten Raudssus + =head1 LICENSE This library is free software. You can redistribute it and/or modify