comparison body_chunked.t @ 1954:5cf0e07d63a1

Tests: tests for request body chunked extensions and trailers.
author Maxim Dounin <mdounin@mdounin.ru>
date Sat, 30 Mar 2024 07:48:42 +0300
parents 2a0a6035a1af
children
comparison
equal deleted inserted replaced
1953:33b54de4ee23 1954:5cf0e07d63a1
20 ############################################################################### 20 ###############################################################################
21 21
22 select STDERR; $| = 1; 22 select STDERR; $| = 1;
23 select STDOUT; $| = 1; 23 select STDOUT; $| = 1;
24 24
25 my $t = Test::Nginx->new()->has(qw/http proxy rewrite/)->plan(18); 25 my $t = Test::Nginx->new()->has(qw/http proxy rewrite/)->plan(24);
26 26
27 $t->write_file_expand('nginx.conf', <<'EOF'); 27 $t->write_file_expand('nginx.conf', <<'EOF');
28 28
29 %%TEST_GLOBALS%% 29 %%TEST_GLOBALS%%
30 30
66 add_header X-Body-File "$request_body_file"; 66 add_header X-Body-File "$request_body_file";
67 proxy_pass http://127.0.0.1:8081; 67 proxy_pass http://127.0.0.1:8081;
68 } 68 }
69 location /large { 69 location /large {
70 client_max_body_size 1k; 70 client_max_body_size 1k;
71 client_body_buffer_size 2k;
71 proxy_pass http://127.0.0.1:8081; 72 proxy_pass http://127.0.0.1:8081;
72 } 73 }
73 location /discard { 74 location /discard {
74 return 200 "TEST\n"; 75 return 200 "TEST\n";
75 } 76 }
117 118
118 like(http_get_body('/single', '0123456789' x 128), 119 like(http_get_body('/single', '0123456789' x 128),
119 qr/X-Body: (0123456789){128}\x0d?$/ms, 'body in single buffer'); 120 qr/X-Body: (0123456789){128}\x0d?$/ms, 'body in single buffer');
120 121
121 like(http_get_body('/large', '0123456789' x 128), qr/ 413 /, 'body too large'); 122 like(http_get_body('/large', '0123456789' x 128), qr/ 413 /, 'body too large');
123 like(http_get_body('/large', 'X' x 1024), qr/ 200 /, 'body exact limit');
124 like(http_get_body('/large', 'X' x 1025), qr/ 413 /, 'body just above limit');
122 125
123 # pipelined requests 126 # pipelined requests
124 127
125 like(http_get_body('/', '0123456789', '0123456789' x 128, '0123456789' x 512, 128 like(http_get_body('/', '0123456789', '0123456789' x 128, '0123456789' x 512,
126 'foobar'), qr/X-Body: foobar\x0d?$/ms, 'chunked body pipelined'); 129 'foobar'), qr/X-Body: foobar\x0d?$/ms, 'chunked body pipelined');
159 . 'SEE-THIS' . CRLF 162 . 'SEE-THIS' . CRLF
160 . '0' . CRLF . CRLF 163 . '0' . CRLF . CRLF
161 ), 164 ),
162 qr/400 Bad/, 'runaway chunk discard' 165 qr/400 Bad/, 'runaway chunk discard'
163 ); 166 );
167
168 # chunk extensions and trailers
169
170 like(
171 http(
172 'GET /large HTTP/1.1' . CRLF
173 . 'Host: localhost' . CRLF
174 . 'Connection: close' . CRLF
175 . 'Transfer-Encoding: chunked' . CRLF . CRLF
176 . ('1; foo' . CRLF . 'X' . CRLF) x 16
177 . '0' . CRLF . CRLF
178 ),
179 qr/ 200 /, 'chunk extensions'
180 );
181
182 TODO: {
183 local $TODO = 'not yet' unless $t->has_version('1.25.5');
184
185 like(
186 http(
187 'GET /large HTTP/1.1' . CRLF
188 . 'Host: localhost' . CRLF
189 . 'Connection: close' . CRLF
190 . 'Transfer-Encoding: chunked' . CRLF . CRLF
191 . ('1; foo' . CRLF . 'X' . CRLF) x 512
192 . '0' . CRLF . CRLF
193 ),
194 qr/ 413 /, 'too many chunk extensions'
195 );
196
197 }
198
199 like(
200 http(
201 'GET /large HTTP/1.1' . CRLF
202 . 'Host: localhost' . CRLF
203 . 'Connection: close' . CRLF
204 . 'Transfer-Encoding: chunked' . CRLF . CRLF
205 . '1' . CRLF . 'X' . CRLF
206 . '0' . CRLF . ('X-Trailer: foo' . CRLF) x 16 . CRLF
207 ),
208 qr/ 200 /, 'trailers'
209 );
210
211 TODO: {
212 local $TODO = 'not yet' unless $t->has_version('1.25.5');
213
214 like(
215 http(
216 'GET /large HTTP/1.1' . CRLF
217 . 'Host: localhost' . CRLF
218 . 'Connection: close' . CRLF
219 . 'Transfer-Encoding: chunked' . CRLF . CRLF
220 . '1' . CRLF . 'X' . CRLF
221 . '0' . CRLF . ('X-Trailer: foo' . CRLF) x 512 . CRLF
222 ),
223 qr/ 413 /, 'too many trailers'
224 );
225
226 }
164 227
165 # proxy_next_upstream 228 # proxy_next_upstream
166 229
167 like(http_get_body('/next', '0123456789'), 230 like(http_get_body('/next', '0123456789'),
168 qr/X-Body: 0123456789\x0d?$/ms, 'body chunked next upstream'); 231 qr/X-Body: 0123456789\x0d?$/ms, 'body chunked next upstream');