Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

always set psgi.input to be buffered even when Content-Type is not set #656

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions lib/Plack/Request.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
37 changes: 37 additions & 0 deletions t/Plack-Request/body-unbuffered.t
Original file line number Diff line number Diff line change
@@ -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;