Skip to content

Commit

Permalink
Merge pull request #653 from haarg/fix-test-empty-delayed-writer
Browse files Browse the repository at this point in the history
fix HTTP::Message::PSGI handling a delayed writer with no content
  • Loading branch information
miyagawa authored Nov 2, 2020
2 parents 7435902 + 010e807 commit 854de22
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/HTTP/Message/PSGI.pm
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,9 @@ sub _res_from_psgi {
};

if (!defined $body) {
$body = [];
my $o = Plack::Util::inline_object
write => sub { push @{ $body ||= [] }, @_ },
write => sub { push @$body, @_ },
close => $convert_resp;

return $o;
Expand Down
23 changes: 23 additions & 0 deletions t/HTTP-Message-PSGI/empty_delayed_writer.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use strict;
use warnings;
use Test::More;
use HTTP::Message::PSGI;
use HTTP::Request;
use HTTP::Response;

my $app = sub {
my ($env) = @_;
return sub {
my ($responder) = @_;
my $writer = $responder->([ 200, [] ]);
$writer->close;
};
};

my $env = req_to_psgi(HTTP::Request->new(POST => "http://localhost/post", [ ], 'hello'));

my $response = HTTP::Response->from_psgi($app->($env));

is($response->content, '', 'delayed writer without write gives empty content');

done_testing;

0 comments on commit 854de22

Please sign in to comment.