Skip to content

Instantly share code, notes, and snippets.

@nihen
Created June 1, 2010 09:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nihen/420748 to your computer and use it in GitHub Desktop.
Save nihen/420748 to your computer and use it in GitHub Desktop.
diff --git a/lib/Plack/Test/Suite.pm b/lib/Plack/Test/Suite.pm
index 7189243..c575ce5 100644
--- a/lib/Plack/Test/Suite.pm
+++ b/lib/Plack/Test/Suite.pm
@@ -614,6 +614,24 @@ our @TEST = (
return [ 200, [ "Content-Type", "text/plain" ], [ "OK" ] ];
},
],
+ [
+ 'Content-Length => 0 is not set Transfer-Encoding # regression test',
+ sub {
+ my $cb = shift;
+ my $res = $cb->(GET "http://127.0.0.1/");
+ is $res->code, 200;
+ is $res->header('Client-Transfer-Encoding'), undef;
+ is $res->content, '';
+ },
+ sub {
+ my $env = shift;
+ return [
+ 200,
+ [ 'Content-Length' => '0' ],
+ ['' ],
+ ];
+ },
+ ],
);
sub runtests {
diff --git a/lib/Starman/Server.pm b/lib/Starman/Server.pm
index bf11ed4..1ae048e 100644
--- a/lib/Starman/Server.pm
+++ b/lib/Starman/Server.pm
@@ -408,7 +408,7 @@ sub _finalize_response {
}
if ( $protocol eq 'HTTP/1.1' ) {
- if ( !$headers{'content-length'} ) {
+ if ( !exists $headers{'content-length'} ) {
if ( $status !~ /^1\d\d|[23]04$/ ) {
DEBUG && warn "[$$] Using chunked transfer-encoding to send unknown length body\n";
push @headers, 'Transfer-Encoding: chunked';
@@ -422,7 +422,7 @@ sub _finalize_response {
}
}
} else {
- if ( !$headers{'content-length'} ) {
+ if ( !exists $headers{'content-length'} ) {
DEBUG && warn "[$$] Disabling keep-alive after sending unknown length body on $protocol\n";
$self->{client}->{keepalive} = 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment