Subject: | Provide body content via body() for URL-encoded forms too |
At present, the HTTP::Body::UrlEncoded parser does not store the request body, it only parses it into params. This means that a request parsed using that parser will not allow the user to get at the raw request as a filehandle via the body() accessor, which leads to unpleasant surprises.
For reference, this came up in https://github.com/PerlDancer/Dancer/issues/1140
I think it would be sane for this parser to store the body just like other parsers do, so that the user can access the raw request body if they wish to do so.
I've attached a simple patch which would make this happen. Would this be considered to be merged and released in the near future? I'm trying to fix this problem for Dancer users, and one option is to replace the use of HTTP::Body, as Plack has done, but I would rather see the behaviour "fixed" in HTTP::Body to be honest.
Cheers
Dave P (bigpresh)
Subject: | http-body-urlencoded-store-body.diff |
--- a/lib/HTTP/Body/UrlEncoded.pm
+++ b/lib/HTTP/Body/UrlEncoded.pm
@@ -36,6 +36,18 @@ HTTP Body UrlEncoded Parser.
sub spin {
my $self = shift;
+ # Still Copy buffer to body temp file, just like other parsers - some users
+ # will expect to be able to get at the raw body with the body method still
+ # (not unreasonably)
+ unless ($self->body) {
+ $self->body(File::Temp->new(DIR => $self->tmpdir));
+ }
+
+ if (my $length = length($self->{buffer})) {
+ $self->body->write(substr($self->{buffer}, 0, $length, ''),
+ $length);
+ }
+
return unless $self->length == $self->content_length;