comparison h2_request_body.t @ 1728:6d5ecf445e57

Tests: added HTTP/2 test with big request body. Notably, it is useful with body buffering in filters, in which case the stream window is flow controlled based on the preread buffer.
author Sergey Kandaurov <pluknet@nginx.com>
date Sat, 04 Sep 2021 14:50:02 +0300
parents 6842b0f7fb9e
children 236d038dc04a
comparison
equal deleted inserted replaced
1727:bdefe70ae1a7 1728:6d5ecf445e57
21 ############################################################################### 21 ###############################################################################
22 22
23 select STDERR; $| = 1; 23 select STDERR; $| = 1;
24 select STDOUT; $| = 1; 24 select STDOUT; $| = 1;
25 25
26 my $t = Test::Nginx->new()->has(qw/http http_v2 proxy/)->plan(45); 26 my $t = Test::Nginx->new()->has(qw/http http_v2 proxy/)->plan(49);
27 27
28 $t->write_file_expand('nginx.conf', <<'EOF'); 28 $t->write_file_expand('nginx.conf', <<'EOF');
29 29
30 %%TEST_GLOBALS%% 30 %%TEST_GLOBALS%%
31 31
136 is(read_body_file($frame->{headers}->{'x-body-file'}), 'TESTMOREDATA', 136 is(read_body_file($frame->{headers}->{'x-body-file'}), 'TESTMOREDATA',
137 'request body in multiple frames separately'); 137 'request body in multiple frames separately');
138 is($frame->{headers}->{'x-length'}, 12, 138 is($frame->{headers}->{'x-length'}, 12,
139 'request body in multiple frames separately - content length'); 139 'request body in multiple frames separately - content length');
140 140
141 # if run with body buffering in filters, it's expected to update window
142 # after request body populates initial stream window size set for preread
143
144 $s = Test::Nginx::HTTP2->new();
145 $sid = $s->new_stream({ path => '/proxy2/t.html', body_more => 1 });
146 $s->h2_body('01234567' x 2048, { body_more => 1 });
147 select undef, undef, undef, 0.1;
148 $s->h2_body('01234567' x 2048, { body_more => 1 });
149 select undef, undef, undef, 0.1;
150 $s->h2_body('01234567' x 2048, { body_more => 1 });
151 select undef, undef, undef, 0.1;
152 $s->h2_body('01234567' x 2048, { body_more => 1 });
153
154 $frames = $s->read(all => [{ type => 'WINDOW_UPDATE' }]);
155 ($frame) = grep { $_->{type} eq 'WINDOW_UPDATE' } @$frames;
156 is($frame->{sid}, $sid, 'big request body - WINDOW_UPDATE sid');
157 cmp_ok($frame->{wdelta}, '>=', 65536, 'big request body - WINDOW_UPDATE delta');
158
159 $s->h2_body('01234567' x 2048);
160
161 $frames = $s->read(all => [{ sid => $sid, fin => 1 }]);
162 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames;
163 is(read_body_file($frame->{headers}->{'x-body-file'}), '01234567' x 10240,
164 'big request body - content');
165 is($frame->{headers}->{'x-length'}, 81920,
166 'big request body - content length');
167
141 # request body with an empty DATA frame 168 # request body with an empty DATA frame
142 # "zero size buf in output" alerts seen 169 # "zero size buf in output" alerts seen
143 170
144 $s = Test::Nginx::HTTP2->new(); 171 $s = Test::Nginx::HTTP2->new();
145 $sid = $s->new_stream({ path => '/proxy2/', body => '' }); 172 $sid = $s->new_stream({ path => '/proxy2/', body => '' });