Mercurial > hg > nginx-tests
comparison h2_request_body.t @ 1721:6842b0f7fb9e
Tests: restored HTTP/2 request body tests with Content-Length.
This partially reverts 3a334b20208e, which prevented testing request body
with Content-Length. Arguably, it appeared as an early attempt to address
new implementation requirements in 0aa07850922f (1.9.15) for request body
flow control. After the HTTP/2 request body preread buffer introduction
in ce94f07d5082 (1.11.0), and emitting HTTP/2 SETTINGS acknowledgement in
tests since 48d277065309, it became barely necessary, if ever.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Tue, 20 Jul 2021 16:12:54 +0300 |
parents | 5ac6efbe5552 |
children | 6d5ecf445e57 |
comparison
equal
deleted
inserted
replaced
1720:efc502e696b0 | 1721:6842b0f7fb9e |
---|---|
82 ############################################################################### | 82 ############################################################################### |
83 | 83 |
84 # request body (uses proxied response) | 84 # request body (uses proxied response) |
85 | 85 |
86 my $s = Test::Nginx::HTTP2->new(); | 86 my $s = Test::Nginx::HTTP2->new(); |
87 my $sid = $s->new_stream({ path => '/proxy2/t.html', body_more => 1 }); | 87 my $sid = $s->new_stream({ path => '/proxy2/t.html', body => 'TEST' }); |
88 $s->h2_body('TEST'); | |
89 my $frames = $s->read(all => [{ sid => $sid, fin => 1 }]); | 88 my $frames = $s->read(all => [{ sid => $sid, fin => 1 }]); |
90 | 89 |
91 my ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | 90 my ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; |
92 is(read_body_file($frame->{headers}->{'x-body-file'}), 'TEST', 'request body'); | 91 is(read_body_file($frame->{headers}->{'x-body-file'}), 'TEST', 'request body'); |
93 is($frame->{headers}->{'x-length'}, 4, 'request body - content length'); | 92 is($frame->{headers}->{'x-length'}, 4, 'request body - content length'); |
94 | 93 |
95 # request body with padding (uses proxied response) | 94 # request body with padding (uses proxied response) |
96 | 95 |
97 $s = Test::Nginx::HTTP2->new(); | 96 $s = Test::Nginx::HTTP2->new(); |
98 $sid = $s->new_stream({ path => '/proxy2/t.html', body_more => 1 }); | 97 $sid = $s->new_stream( |
99 $s->h2_body('TEST', { body_padding => 42 }); | 98 { path => '/proxy2/t.html', body => 'TEST', body_padding => 42 }); |
100 $frames = $s->read(all => [{ sid => $sid, fin => 1 }]); | 99 $frames = $s->read(all => [{ sid => $sid, fin => 1 }]); |
101 | 100 |
102 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | 101 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; |
103 is(read_body_file($frame->{headers}->{'x-body-file'}), 'TEST', | 102 is(read_body_file($frame->{headers}->{'x-body-file'}), 'TEST', |
104 'request body with padding'); | 103 'request body with padding'); |
112 is($frame->{headers}->{':status'}, '200', 'request body with padding - next'); | 111 is($frame->{headers}->{':status'}, '200', 'request body with padding - next'); |
113 | 112 |
114 # request body sent in multiple DATA frames in a single packet | 113 # request body sent in multiple DATA frames in a single packet |
115 | 114 |
116 $s = Test::Nginx::HTTP2->new(); | 115 $s = Test::Nginx::HTTP2->new(); |
117 $sid = $s->new_stream({ path => '/proxy2/t.html', body_more => 1 }); | 116 $sid = $s->new_stream( |
118 $s->h2_body('TEST', { body_split => [2] }); | 117 { path => '/proxy2/t.html', body => 'TEST', body_split => [2] }); |
119 $frames = $s->read(all => [{ sid => $sid, fin => 1 }]); | 118 $frames = $s->read(all => [{ sid => $sid, fin => 1 }]); |
120 | 119 |
121 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | 120 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; |
122 is(read_body_file($frame->{headers}->{'x-body-file'}), 'TEST', | 121 is(read_body_file($frame->{headers}->{'x-body-file'}), 'TEST', |
123 'request body in multiple frames'); | 122 'request body in multiple frames'); |
141 | 140 |
142 # request body with an empty DATA frame | 141 # request body with an empty DATA frame |
143 # "zero size buf in output" alerts seen | 142 # "zero size buf in output" alerts seen |
144 | 143 |
145 $s = Test::Nginx::HTTP2->new(); | 144 $s = Test::Nginx::HTTP2->new(); |
146 $sid = $s->new_stream({ path => '/proxy2/', body_more => 1 }); | 145 $sid = $s->new_stream({ path => '/proxy2/', body => '' }); |
147 $s->h2_body(''); | |
148 $frames = $s->read(all => [{ sid => $sid, fin => 1 }]); | 146 $frames = $s->read(all => [{ sid => $sid, fin => 1 }]); |
149 | 147 |
150 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | 148 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; |
151 is($frame->{headers}->{':status'}, 200, 'request body - empty'); | 149 is($frame->{headers}->{':status'}, 200, 'request body - empty'); |
152 is($frame->{headers}->{'x-length'}, 0, 'request body - empty size'); | 150 is($frame->{headers}->{'x-length'}, 0, 'request body - empty size'); |
176 is($frame->{code}, 0, 'request body discarded - zero RST_STREAM'); | 174 is($frame->{code}, 0, 'request body discarded - zero RST_STREAM'); |
177 | 175 |
178 # malformed request body length not equal to content-length | 176 # malformed request body length not equal to content-length |
179 | 177 |
180 $s = Test::Nginx::HTTP2->new(); | 178 $s = Test::Nginx::HTTP2->new(); |
181 $sid = $s->new_stream({ body_more => 1, headers => [ | 179 $sid = $s->new_stream({ body => 'TEST', headers => [ |
182 { name => ':method', value => 'GET', mode => 0 }, | 180 { name => ':method', value => 'GET', mode => 0 }, |
183 { name => ':scheme', value => 'http', mode => 0 }, | 181 { name => ':scheme', value => 'http', mode => 0 }, |
184 { name => ':path', value => '/client_max_body_size', mode => 1 }, | 182 { name => ':path', value => '/client_max_body_size', mode => 1 }, |
185 { name => ':authority', value => 'localhost', mode => 1 }, | 183 { name => ':authority', value => 'localhost', mode => 1 }, |
186 { name => 'content-length', value => '5', mode => 1 }]}); | 184 { name => 'content-length', value => '5', mode => 1 }]}); |
187 $s->h2_body('TEST'); | |
188 $frames = $s->read(all => [{ sid => $sid, fin => 1 }]); | 185 $frames = $s->read(all => [{ sid => $sid, fin => 1 }]); |
189 | 186 |
190 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | 187 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; |
191 is($frame->{headers}->{':status'}, 400, 'request body less than content-length'); | 188 is($frame->{headers}->{':status'}, 400, 'request body less than content-length'); |
192 | 189 |
193 $sid = $s->new_stream({ body_more => 1, headers => [ | 190 $sid = $s->new_stream({ body => 'TEST', headers => [ |
194 { name => ':method', value => 'GET', mode => 0 }, | 191 { name => ':method', value => 'GET', mode => 0 }, |
195 { name => ':scheme', value => 'http', mode => 0 }, | 192 { name => ':scheme', value => 'http', mode => 0 }, |
196 { name => ':path', value => '/client_max_body_size', mode => 1 }, | 193 { name => ':path', value => '/client_max_body_size', mode => 1 }, |
197 { name => ':authority', value => 'localhost', mode => 1 }, | 194 { name => ':authority', value => 'localhost', mode => 1 }, |
198 { name => 'content-length', value => '3', mode => 1 }]}); | 195 { name => 'content-length', value => '3', mode => 1 }]}); |
199 $s->h2_body('TEST'); | |
200 $frames = $s->read(all => [{ sid => $sid, fin => 1 }]); | 196 $frames = $s->read(all => [{ sid => $sid, fin => 1 }]); |
201 | 197 |
202 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | 198 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; |
203 is($frame->{headers}->{':status'}, 400, 'request body more than content-length'); | 199 is($frame->{headers}->{':status'}, 400, 'request body more than content-length'); |
204 | 200 |
205 # client_max_body_size | 201 # client_max_body_size |
206 | 202 |
207 $s = Test::Nginx::HTTP2->new(); | 203 $s = Test::Nginx::HTTP2->new(); |
208 $sid = $s->new_stream({ path => '/client_max_body_size/t.html', | 204 $sid = $s->new_stream({ path => '/client_max_body_size/t.html', |
209 body_more => 1 }); | 205 body => 'TESTTEST12' }); |
210 $s->h2_body('TESTTEST12'); | |
211 $frames = $s->read(all => [{ sid => $sid, fin => 1 }]); | 206 $frames = $s->read(all => [{ sid => $sid, fin => 1 }]); |
212 | 207 |
213 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | 208 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; |
214 is($frame->{headers}->{':status'}, 200, 'client_max_body_size - status'); | 209 is($frame->{headers}->{':status'}, 200, 'client_max_body_size - status'); |
215 is(read_body_file($frame->{headers}->{'x-body-file'}), 'TESTTEST12', | 210 is(read_body_file($frame->{headers}->{'x-body-file'}), 'TESTTEST12', |
217 | 212 |
218 # client_max_body_size - limited | 213 # client_max_body_size - limited |
219 | 214 |
220 $s = Test::Nginx::HTTP2->new(); | 215 $s = Test::Nginx::HTTP2->new(); |
221 $sid = $s->new_stream({ path => '/client_max_body_size/t.html', | 216 $sid = $s->new_stream({ path => '/client_max_body_size/t.html', |
222 body_more => 1 }); | 217 body => 'TESTTEST123' }); |
223 $s->h2_body('TESTTEST123'); | |
224 $frames = $s->read(all => [{ sid => $sid, fin => 1 }]); | 218 $frames = $s->read(all => [{ sid => $sid, fin => 1 }]); |
225 | 219 |
226 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | 220 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; |
227 is($frame->{headers}->{':status'}, 413, 'client_max_body_size - limited'); | 221 is($frame->{headers}->{':status'}, 413, 'client_max_body_size - limited'); |
228 | 222 |
229 # client_max_body_size - many DATA frames | 223 # client_max_body_size - many DATA frames |
230 | 224 |
231 $s = Test::Nginx::HTTP2->new(); | 225 $s = Test::Nginx::HTTP2->new(); |
232 $sid = $s->new_stream({ path => '/client_max_body_size/t.html', | 226 $sid = $s->new_stream({ path => '/client_max_body_size/t.html', |
233 body_more => 1 }); | 227 body => 'TESTTEST12', body_split => [2] }); |
234 $s->h2_body('TESTTEST12', { body_split => [2] }); | |
235 $frames = $s->read(all => [{ sid => $sid, fin => 1 }]); | 228 $frames = $s->read(all => [{ sid => $sid, fin => 1 }]); |
236 | 229 |
237 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | 230 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; |
238 is($frame->{headers}->{':status'}, 200, 'client_max_body_size many - status'); | 231 is($frame->{headers}->{':status'}, 200, 'client_max_body_size many - status'); |
239 is(read_body_file($frame->{headers}->{'x-body-file'}), 'TESTTEST12', | 232 is(read_body_file($frame->{headers}->{'x-body-file'}), 'TESTTEST12', |
241 | 234 |
242 # client_max_body_size - many DATA frames - limited | 235 # client_max_body_size - many DATA frames - limited |
243 | 236 |
244 $s = Test::Nginx::HTTP2->new(); | 237 $s = Test::Nginx::HTTP2->new(); |
245 $sid = $s->new_stream({ path => '/client_max_body_size/t.html', | 238 $sid = $s->new_stream({ path => '/client_max_body_size/t.html', |
246 body_more => 1 }); | 239 body => 'TESTTEST123', body_split => [2] }); |
247 $s->h2_body('TESTTEST123', { body_split => [2] }); | |
248 $frames = $s->read(all => [{ sid => $sid, fin => 1 }]); | 240 $frames = $s->read(all => [{ sid => $sid, fin => 1 }]); |
249 | 241 |
250 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | 242 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; |
251 is($frame->{headers}->{':status'}, 413, 'client_max_body_size many - limited'); | 243 is($frame->{headers}->{':status'}, 413, 'client_max_body_size many - limited'); |
252 | 244 |
253 # client_max_body_size - padded DATA | 245 # client_max_body_size - padded DATA |
254 | 246 |
255 $s = Test::Nginx::HTTP2->new(); | 247 $s = Test::Nginx::HTTP2->new(); |
256 $sid = $s->new_stream({ path => '/client_max_body_size/t.html', | 248 $sid = $s->new_stream({ path => '/client_max_body_size/t.html', |
257 body_more => 1 }); | 249 body => 'TESTTEST12', body_padding => 42 }); |
258 $s->h2_body('TESTTEST12', { body_padding => 42 }); | |
259 $frames = $s->read(all => [{ sid => $sid, fin => 1 }]); | 250 $frames = $s->read(all => [{ sid => $sid, fin => 1 }]); |
260 | 251 |
261 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | 252 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; |
262 is($frame->{headers}->{':status'}, 200, 'client_max_body_size pad - status'); | 253 is($frame->{headers}->{':status'}, 200, 'client_max_body_size pad - status'); |
263 is(read_body_file($frame->{headers}->{'x-body-file'}), 'TESTTEST12', | 254 is(read_body_file($frame->{headers}->{'x-body-file'}), 'TESTTEST12', |
265 | 256 |
266 # client_max_body_size - padded DATA - limited | 257 # client_max_body_size - padded DATA - limited |
267 | 258 |
268 $s = Test::Nginx::HTTP2->new(); | 259 $s = Test::Nginx::HTTP2->new(); |
269 $sid = $s->new_stream({ path => '/client_max_body_size/t.html', | 260 $sid = $s->new_stream({ path => '/client_max_body_size/t.html', |
270 body_more => 1 }); | 261 body => 'TESTTEST123', body_padding => 42 }); |
271 $s->h2_body('TESTTEST123', { body_padding => 42 }); | |
272 $frames = $s->read(all => [{ sid => $sid, fin => 1 }]); | 262 $frames = $s->read(all => [{ sid => $sid, fin => 1 }]); |
273 | 263 |
274 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | 264 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; |
275 is($frame->{headers}->{':status'}, 413, 'client_max_body_size pad - limited'); | 265 is($frame->{headers}->{':status'}, 413, 'client_max_body_size pad - limited'); |
276 | 266 |
277 # client_max_body_size - many padded DATA frames | 267 # client_max_body_size - many padded DATA frames |
278 | 268 |
279 $s = Test::Nginx::HTTP2->new(); | 269 $s = Test::Nginx::HTTP2->new(); |
280 $sid = $s->new_stream({ path => '/client_max_body_size/t.html', | 270 $sid = $s->new_stream({ path => '/client_max_body_size/t.html', |
281 body_more => 1 }); | 271 body => 'TESTTEST12', body_padding => 42, body_split => [2] }); |
282 $s->h2_body('TESTTEST12', { body_padding => 42, body_split => [2] }); | |
283 $frames = $s->read(all => [{ sid => $sid, fin => 1 }]); | 272 $frames = $s->read(all => [{ sid => $sid, fin => 1 }]); |
284 | 273 |
285 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | 274 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; |
286 is($frame->{headers}->{':status'}, 200, | 275 is($frame->{headers}->{':status'}, 200, |
287 'client_max_body_size many pad - status'); | 276 'client_max_body_size many pad - status'); |
290 | 279 |
291 # client_max_body_size - many padded DATA frames - limited | 280 # client_max_body_size - many padded DATA frames - limited |
292 | 281 |
293 $s = Test::Nginx::HTTP2->new(); | 282 $s = Test::Nginx::HTTP2->new(); |
294 $sid = $s->new_stream({ path => '/client_max_body_size/t.html', | 283 $sid = $s->new_stream({ path => '/client_max_body_size/t.html', |
295 body_more => 1 }); | 284 body => 'TESTTEST123', body_padding => 42, body_split => [2] }); |
296 $s->h2_body('TESTTEST123', { body_padding => 42, body_split => [2] }); | |
297 $frames = $s->read(all => [{ sid => $sid, fin => 1 }]); | 285 $frames = $s->read(all => [{ sid => $sid, fin => 1 }]); |
298 | 286 |
299 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | 287 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; |
300 is($frame->{headers}->{':status'}, 413, | 288 is($frame->{headers}->{':status'}, 413, |
301 'client_max_body_size many pad - limited'); | 289 'client_max_body_size many pad - limited'); |