Skip to content

Commit

Permalink
Merge pull request #437 from wchristian/http-msg-invalid-response
Browse files Browse the repository at this point in the history
make HTTP::Message::PSGI complain loudly about invalid PSGI responses
  • Loading branch information
miyagawa committed Dec 3, 2013
2 parents 2e78e6f + 1dffb9c commit d3fc874
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/HTTP/Message/PSGI.pm
Expand Up @@ -105,6 +105,10 @@ sub res_from_psgi {
_res_from_psgi($_[0], \$res);
});
}
else {
my $response = defined $psgi_res ? "'$psgi_res'" : 'undef';
die "Bad response $response";
}

return $res;
}
Expand Down
20 changes: 20 additions & 0 deletions t/HTTP-Message-PSGI/unknown_response.t
@@ -0,0 +1,20 @@
use strict;
use warnings;
use Test::More;
use HTTP::Message::PSGI;
use HTTP::Request;
use HTTP::Response;

my $res;
my $app = sub { $res };
my $env = req_to_psgi(HTTP::Request->new(GET => "http://localhost/"));

eval { HTTP::Response->from_psgi($app->($env)) };
like($@, qr/Bad response undef/, 'converting undef PSGI response results in error');

$res = 5;

eval { HTTP::Response->from_psgi($app->($env)) };
like($@, qr/Bad response '5'/, 'converting invalid PSGI response results in error');

done_testing;

0 comments on commit d3fc874

Please sign in to comment.