diff --git a/lib/HTTP/Message/PSGI.pm b/lib/HTTP/Message/PSGI.pm index 07d2c07f0..f2fce9cfc 100644 --- a/lib/HTTP/Message/PSGI.pm +++ b/lib/HTTP/Message/PSGI.pm @@ -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; diff --git a/t/HTTP-Message-PSGI/empty_delayed_writer.t b/t/HTTP-Message-PSGI/empty_delayed_writer.t new file mode 100644 index 000000000..62312303c --- /dev/null +++ b/t/HTTP-Message-PSGI/empty_delayed_writer.t @@ -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;