Skip to content

Commit 5b45159

Browse files
committed
Tests: reworked proxy_unfinished.t to use http_content().
This somewhat simplifies tests and makes it possible to better check for unexpected corruption of chunked responses, such as the one recently fixed in nginx-quic experimental branch.
1 parent 758f406 commit 5b45159

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

lib/Test/Nginx.pm

+7-1
Original file line numberDiff line numberDiff line change
@@ -853,12 +853,18 @@ sub http_content {
853853
}
854854

855855
my $content = '';
856+
my $len = -1;
857+
856858
while ($body =~ /\G\x0d?\x0a?([0-9a-f]+)\x0d\x0a?/gcmsi) {
857-
my $len = hex($1);
859+
$len = hex($1);
858860
$content .= substr($body, pos($body), $len);
859861
pos($body) += $len;
860862
}
861863

864+
if ($len != 0) {
865+
$content .= '[no-last-chunk]';
866+
}
867+
862868
return $content;
863869
}
864870

proxy_unfinished.t

+11-11
Original file line numberDiff line numberDiff line change
@@ -105,28 +105,28 @@ like(http_get('/cache/chunked'), qr/MISS/, 'unfinished chunked');
105105

106106
# make sure there is no final chunk in unfinished responses
107107

108-
like(http_get_11('/length'), qr/unfinished(?!.*\x0d\x0a?0\x0d\x0a?)/s,
108+
like(http_get_11('/length'), qr/unfinished.*no-last-chunk/s,
109109
'length no final chunk');
110-
like(http_get_11('/chunked'), qr/unfinished(?!.*\x0d\x0a?0\x0d\x0a?)/s,
110+
like(http_get_11('/chunked'), qr/unfinished.*no-last-chunk/s,
111111
'chunked no final chunk');
112112

113113
# but there is final chunk in complete responses
114114

115-
like(http_get_11('/length/ok'), qr/finished.*\x0d\x0a?0\x0d\x0a?/s,
115+
like(http_get_11('/length/ok'), qr/finished\x0d\x0a$/s,
116116
'length final chunk');
117-
like(http_get_11('/chunked/ok'), qr/finished.*\x0d\x0a?0\x0d\x0a?/s,
117+
like(http_get_11('/chunked/ok'), qr/finished\x0d\x0a$/s,
118118
'chunked final chunk');
119119

120120
# the same with proxy_buffering set to off
121121

122-
like(http_get_11('/un/length'), qr/unfinished(?!.*\x0d\x0a?0\x0d\x0a?)/s,
122+
like(http_get_11('/un/length'), qr/unfinished.*no-last-chunk/s,
123123
'unbuffered length no final chunk');
124-
like(http_get_11('/un/chunked'), qr/unfinished(?!.*\x0d\x0a?0\x0d\x0a?)/s,
124+
like(http_get_11('/un/chunked'), qr/unfinished.*no-last-chunk/s,
125125
'unbuffered chunked no final chunk');
126126

127-
like(http_get_11('/un/length/ok'), qr/finished.*\x0d\x0a?0\x0d\x0a?/s,
127+
like(http_get_11('/un/length/ok'), qr/finished\x0d\x0a$/s,
128128
'unbuffered length final chunk');
129-
like(http_get_11('/un/chunked/ok'), qr/finished.*\x0d\x0a?0\x0d\x0a?/s,
129+
like(http_get_11('/un/chunked/ok'), qr/finished\x0d\x0a$/s,
130130
'unbuffered chunked final chunk');
131131

132132
# big responses
@@ -144,7 +144,7 @@ chmod(0000, $t->testdir() . '/proxy_temp');
144144
my $r = http_get_11('/proxy/big.html', sleep => 0.5);
145145

146146
SKIP: {
147-
skip 'finished', 1 if length(http_content($r)) == 1024 * 1024 + 8;
147+
skip 'finished', 1 if length($r) == 1024 * 1024 + 8;
148148

149149
like($r, qr/X(?!.*\x0d\x0a?0\x0d\x0a?)/s, 'no proxy temp');
150150

@@ -157,12 +157,12 @@ chmod(0700, $t->testdir() . '/proxy_temp');
157157
sub http_get_11 {
158158
my ($uri, %extra) = @_;
159159

160-
return http(
160+
return http_content(http(
161161
"GET $uri HTTP/1.1" . CRLF .
162162
"Connection: close" . CRLF .
163163
"Host: localhost" . CRLF . CRLF,
164164
%extra
165-
);
165+
));
166166
}
167167

168168
###############################################################################

0 commit comments

Comments
 (0)