Skip Menu |

This queue is for tickets about the Net-Async-HTTP-Server CPAN distribution.

Report information
The Basics
Id: 98985
Status: resolved
Priority: 0/
Queue: Net-Async-HTTP-Server

People
Owner: Nobody in particular
Requestors: frioux [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: 0.08



Subject: undef body causes warning
Date: Fri, 19 Sep 2014 11:11:17 -0500
To: bug-Net-Async-HTTP-Server [...] rt.cpan.org
From: fREW Schmidt <frioux [...] gmail.com>
When you have a plack app running under Net::Async::HTTP::Server::PSGI, if it returns something like this: [200, ['Content-type' => 'text/html'], []] You get warnings like this: Use of uninitialized value in addition (+) at /home/frew/.plenv/versions/5.20.1/lib/perl5/site_perl/5.20.1/Net/Async/HTTP/Server/PSGI.pm line 217. Now obviously a user should not return a body like that, but it might be nice if instead of a warning it either warned that the body was empty/missing, or just did || ''. -- fREW Schmidt https://blog.afoolishmanifesto.com
Download (untitled)
application/pgp-signature 819b

Message body not shown because it is not plain text.

On Fri Sep 19 12:10:15 2014, frew wrote: Show quoted text
> When you have a plack app running under > Net::Async::HTTP::Server::PSGI, if it returns something like this: > > [200, ['Content-type' => 'text/html'], []] > > You get warnings like this: > > Use of uninitialized value in addition (+) at > /home/frew/.plenv/versions/5.20.1/lib/perl5/site_perl/5.20.1/Net/Async/HTTP/Server/PSGI.pm > line 217.
Hmm.. So, line 217 looks like: 215 unless( $has_content_length ) { 216 my $len = 0; 217 $len += length $_ for @$body; 218 $response->content_length( $len ); 219 } I suspect the warning above wouldn't come from a body of [], but rather a body such as [undef]. An empty body would be fine. I'll arrange for it to treat it as an empty string but print a one-time warning per response, that there was an undef. -- Paul Evans
The attached patch yields a hopefully more useful warning -- Paul Evans
Subject: rt98985.patch
=== modified file 'lib/Net/Async/HTTP/Server/PSGI.pm' --- lib/Net/Async/HTTP/Server/PSGI.pm 2014-03-26 18:29:01 +0000 +++ lib/Net/Async/HTTP/Server/PSGI.pm 2014-10-09 13:50:01 +0000 @@ -214,7 +214,10 @@ elsif( ref $body eq "ARRAY" ) { unless( $has_content_length ) { my $len = 0; - $len += length $_ for @$body; + my $found_undef; + $len += length( $_ // ( $found_undef++, "" ) ) for @$body; + carp "Found undefined value in PSGI body" if $found_undef; + $response->content_length( $len ); } === modified file 't/20psgi.t' --- t/20psgi.t 2013-12-30 02:40:34 +0000 +++ t/20psgi.t 2014-10-09 13:50:01 +0000 @@ -174,4 +174,28 @@ ok( !exists $received_env->{HTTP_CONTENT_TYPE}, 'no HTTP_CONTENT_TYPE' ); } +# Warnings about undef body (RT98985) +{ + my $warnings = ""; + local $SIG{__WARN__} = sub { $warnings .= join " ", @_ }; + + $server->configure( app => sub { + return [ + 200, + [ "Content-Type" => "text/plain" ], + [ undef ], + ]; + } ); + + $C->syswrite( + "GET / HTTP/1.1$CRLF" . + $CRLF + ); + + my $buffer = ""; + wait_for_stream { $buffer =~ m/$CRLF$CRLF/ } $C => $buffer; + + like( $warnings, qr/undefined value in PSGI body/, 'undef in body yields warning' ); +} + done_testing;
Released in 0.08 -- Paul Evans