diff --git a/lib/Plack/Request.pm b/lib/Plack/Request.pm index e75bd6015..3382ddffd 100644 --- a/lib/Plack/Request.pm +++ b/lib/Plack/Request.pm @@ -251,13 +251,15 @@ sub _buffer_length_for { sub _parse_request_body { my $self = shift; - if ( !$self->env->{CONTENT_TYPE} ) { - $self->env->{'plack.request.body_parameters'} = []; - $self->env->{'plack.request.upload'} = Hash::MultiValue->new(); - return; - } - my ($params,$uploads) = $self->request_body_parser->parse($self->env); + my ($params,$uploads) = do { + # work around HTTP::Entity::Parser issue not replacing psgi.input when Content-Type is not set + local $self->env->{CONTENT_TYPE} = 'application/octet-stream' + unless $self->env->{CONTENT_TYPE}; + + $self->request_body_parser->parse($self->env); + }; + $self->env->{'plack.request.body_parameters'} = $params; my $upload_hash = Hash::MultiValue->new(); diff --git a/t/Plack-Request/body-unbuffered.t b/t/Plack-Request/body-unbuffered.t new file mode 100644 index 000000000..cda8d7405 --- /dev/null +++ b/t/Plack-Request/body-unbuffered.t @@ -0,0 +1,37 @@ +use strict; +use warnings; +use Test::More; +use Plack::Test; +use Plack::Request; +use Plack::Util; +use HTTP::Request::Common; + +my $app = sub { + my $env = shift; + + $env->{'psgix.input.buffered'} = 0; + + my $input = $env->{'psgi.input'}; + $env->{'psgi.input'} = Plack::Util::inline_object + read => sub { $input->read(@_) }; + + my $req = Plack::Request->new($env); + is $req->content, '{}'; + + $req->new_response(200)->finalize; +}; + +test_psgi $app, sub { + my $cb = shift; + + # empty Content-Type + my $req = POST "/"; + $req->content_type(""); + $req->content("{}"); + $req->content_length(2); + + my $res = $cb->($req); + ok $res->is_success or diag $res->as_string; +}; + +done_testing;