[PATCH 2 of 3] Tests: http_end - make getline() work with chunked messages

Shawn J. Goff shawgoff at amazon.com
Sat Jan 3 00:02:50 UTC 2015


# HG changeset patch
# User Shawn J. Goff <shawgoff at amazon.com>
# Date 1419638613 28800
# Node ID 7e0cf8051ecb5c358dfd0bea94aa0aefa744ee29
# Parent  130a511d3faa26f79225dff7ef6796f4d39bc482
Tests: http_end - make getline() work with chunked messages

When testing HTTP/1.1 keep-alive requests, this getline() will hang forever as
it never gets EOF. This change avoids clearing $/ so that getline() will return
for each line. It looks for a last-chunk (CRLF0CRLF) followed by a CRLF to
delimit the message. This means it won't work for a test that uses a
chunk-extension or a trailer, but there are no such tests yet.

diff -r 130a511d3faa -r 7e0cf8051ecb lib/Test/Nginx.pm
--- a/lib/Test/Nginx.pm	Wed Dec 17 17:34:14 2014 -0800
+++ b/lib/Test/Nginx.pm	Fri Dec 26 16:03:33 2014 -0800
@@ -531,9 +531,14 @@
 		local $SIG{PIPE} = sub { die "sigpipe\n" };
 		alarm(5);
 
-		local $/;
-		$reply = $s->getline();
-
+		while (defined(my $line = $s->getline())){
+			$reply = $reply.$line;
+			# finish if we get the last chunk of a chunked-encoding 
+			last if ($reply =~ qr/\x0d\x0a0\x0d\x0a\x0d\x0a$/)
+			# Note: for the sake of a simpler test, this does not
+			# account for a chunk-extension or for a trailer. See
+			# RFC2616#sec3.6.1 for details.
+		}
 		alarm(0);
 	};
 	alarm(0);



More information about the nginx-devel mailing list