comparison perl.t @ 1491:c2bbf805388d

Tests: more perl request body tests.
author Sergey Kandaurov <pluknet@nginx.com>
date Fri, 12 Jul 2019 18:27:11 +0300
parents 8f79fac049df
children 5ac6efbe5552
comparison
equal deleted inserted replaced
1490:8f79fac049df 1491:c2bbf805388d
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 perl rewrite/)->plan(20) 26 my $t = Test::Nginx->new()->has(qw/http perl rewrite/)->plan(24)
27 ->write_file_expand('nginx.conf', <<'EOF'); 27 ->write_file_expand('nginx.conf', <<'EOF');
28 28
29 %%TEST_GLOBALS%% 29 %%TEST_GLOBALS%%
30 30
31 daemon off; 31 daemon off;
105 $r->print("body: ", $r->request_body, "\n"); 105 $r->print("body: ", $r->request_body, "\n");
106 $r->print("file: ", $r->request_body_file, "\n"); 106 $r->print("file: ", $r->request_body_file, "\n");
107 } 107 }
108 }'; 108 }';
109 } 109 }
110
111 location /discard {
112 perl 'sub {
113 use warnings;
114 use strict;
115
116 my $r = shift;
117
118 $r->discard_request_body;
119
120 $r->send_http_header("text/plain");
121
122 return OK if $r->header_only;
123
124 $r->print("host: ", $r->header_in("Host"), "\n");
125
126 return OK;
127 }';
128 }
110 } 129 }
111 } 130 }
112 131
113 EOF 132 EOF
114 133
199 ), qr|200 OK|ms, 'perl precondition failed'); 218 ), qr|200 OK|ms, 'perl precondition failed');
200 219
201 } 220 }
202 221
203 # various request body tests 222 # various request body tests
223
224 like(http_get('/body'), qr/400 Bad Request/, 'perl no body');
204 225
205 like(http( 226 like(http(
206 'GET /body HTTP/1.0' . CRLF 227 'GET /body HTTP/1.0' . CRLF
207 . 'Host: localhost' . CRLF 228 . 'Host: localhost' . CRLF
208 . 'Content-Length: 10' . CRLF . CRLF 229 . 'Content-Length: 10' . CRLF . CRLF
254 . '12345', 275 . '12345',
255 sleep => 0.1, 276 sleep => 0.1,
256 body => '67890' . CRLF . '0' . CRLF . CRLF 277 body => '67890' . CRLF . '0' . CRLF . CRLF
257 ), qr/body: 1234567890/, 'perl body chunked split'); 278 ), qr/body: 1234567890/, 'perl body chunked split');
258 279
280 like(http(
281 'GET /discard HTTP/1.1' . CRLF
282 . 'Host: localhost' . CRLF
283 . 'Connection: close' . CRLF
284 . 'Transfer-Encoding: chunked' . CRLF . CRLF
285 . 'a' . CRLF
286 . '1234567890' . CRLF
287 . '0' . CRLF . CRLF
288 ), qr/host: localhost/, 'perl body discard');
289
290 TODO: {
291 local $TODO = 'not yet' unless $t->has_version('1.17.2');
292
293 like(http(
294 'GET /discard HTTP/1.1' . CRLF
295 . 'Host: localhost' . CRLF
296 . 'Connection: close' . CRLF
297 . 'Transfer-Encoding: chunked' . CRLF . CRLF
298 . 'ak' . CRLF
299 . '1234567890' . CRLF
300 . '0' . CRLF . CRLF
301 ), qr/400 Bad Request/, 'perl body discard bad chunk');
302
303 like(http(
304 'GET /body HTTP/1.1' . CRLF
305 . 'Host: localhost' . CRLF
306 . 'Connection: close' . CRLF
307 . 'Transfer-Encoding: chunked' . CRLF . CRLF
308 . 'ak' . CRLF
309 . '1234567890' . CRLF
310 . '0' . CRLF . CRLF
311 ), qr/400 Bad Request/, 'perl body bad chunk');
312
313 }
314
259 ############################################################################### 315 ###############################################################################