Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

_prepare_env: check definedness instead of value #61

Open
wants to merge 3 commits into from

2 participants

@florolf

Check whether inputbuf is defined instead of evaluating it for truth.

The old behavior caused a body consisting only of "0" to disappear; this
commit fixes the problem.

This is essentially a duplicate of PerlDancer/Dancer#858.

Florian Larysch _prepare_env: check definedness instead of value
Check whether inputbuf is defined instead of evaluating it for truth.

The old behavior caused a body consisting only of "0" to disappear; this
commit fixes the problem.
17d085b
@miyagawa
Owner

Can you provide a unit test to address it?

Florian Larysch added some commits
Florian Larysch add unit test for fix #61
Send a POST-request with a body containing only "0" to an echo
PSGI-Application. This test uses a timeout because the webserver might
block in a pathological case.
fd1004d
Florian Larysch remove unused variable from unit test 03492cf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 16, 2013
  1. _prepare_env: check definedness instead of value

    Florian Larysch authored
    Check whether inputbuf is defined instead of evaluating it for truth.
    
    The old behavior caused a body consisting only of "0" to disappear; this
    commit fixes the problem.
  2. add unit test for fix #61

    Florian Larysch authored
    Send a POST-request with a body containing only "0" to an echo
    PSGI-Application. This test uses a timeout because the webserver might
    block in a pathological case.
  3. remove unused variable from unit test

    Florian Larysch authored
This page is out of date. Refresh to see the latest.
Showing with 44 additions and 1 deletion.
  1. +1 −1  lib/Starman/Server.pm
  2. +43 −0 t/post_zero_body.t
View
2  lib/Starman/Server.pm
@@ -368,7 +368,7 @@ sub _prepare_env {
my($self, $env) = @_;
my $get_chunk = sub {
- if ($self->{client}->{inputbuf}) {
+ if (defined $self->{client}->{inputbuf}) {
my $chunk = delete $self->{client}->{inputbuf};
return ($chunk, length $chunk);
}
View
43 t/post_zero_body.t
@@ -0,0 +1,43 @@
+use strict;
+use Plack::Test;
+use File::ShareDir;
+use HTTP::Request;
+use Test::More;
+use Digest::MD5;
+use LWP::UserAgent;
+
+$Plack::Test::Impl = "Server";
+$ENV{PLACK_SERVER} = 'Starman';
+
+my $app = sub {
+ my $env = shift;
+ my $body;
+ my $clen = $env->{CONTENT_LENGTH};
+ while ($clen > 0) {
+ $env->{'psgi.input'}->read(my $buf, $clen) or last;
+ $clen -= length $buf;
+ $body .= $buf;
+ }
+ return [ 200, [ 'Content-Type', 'text/plain', 'X-Content-Length', $env->{CONTENT_LENGTH} ], [ $body ] ];
+};
+
+
+my $ua = LWP::UserAgent->new;
+$ua->timeout(5);
+
+test_psgi
+ app => $app,
+ client => sub {
+ my $cb = shift;
+
+ my $req = HTTP::Request->new(POST => "http://localhost/");
+ $req->content("0");
+
+ my $res = $cb->($req);
+
+ is $res->header('X-Content-Length'), 1;
+ is Digest::MD5::md5_hex($res->content), 'cfcd208495d565ef66e7dff9f98764da';
+ },
+ ua => $ua;
+
+done_testing;
Something went wrong with that request. Please try again.