Mercurial > hg > nginx-tests
annotate body.t @ 1990:85d88cd5091c
Tests: SSI include stub tests.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 04 Jul 2024 17:42:55 +0300 |
parents | 5ac6efbe5552 |
children |
rev | line source |
---|---|
240
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
2 |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
3 # (C) Maxim Dounin |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
4 |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
5 # Tests for nginx request body reading. |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
6 |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
7 ############################################################################### |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
8 |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
9 use warnings; |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
10 use strict; |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
11 |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
12 use Test::More; |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
13 use Socket qw/ CRLF /; |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
14 |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
15 BEGIN { use FindBin; chdir($FindBin::Bin); } |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
16 |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
17 use lib 'lib'; |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
18 use Test::Nginx; |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
19 |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
20 ############################################################################### |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
21 |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
22 select STDERR; $| = 1; |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
23 select STDOUT; $| = 1; |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
24 |
1539
57a92c20f974
Tests: discarded request body in error_page redirect.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1500
diff
changeset
|
25 my $t = Test::Nginx->new()->has(qw/http proxy rewrite/)->plan(15); |
240
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
26 |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
27 $t->write_file_expand('nginx.conf', <<'EOF'); |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
28 |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
29 %%TEST_GLOBALS%% |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
30 |
249
6a0d934950bc
Tests: remove extra spaces in "daemon off".
Maxim Dounin <mdounin@mdounin.ru>
parents:
240
diff
changeset
|
31 daemon off; |
240
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
32 |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
33 events { |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
34 } |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
35 |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
36 http { |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
37 %%TEST_GLOBALS_HTTP%% |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
38 |
269
970bb423e59f
Tests: proxy_next_upstream tests in body.t, body_chunked.t.
Maxim Dounin <mdounin@mdounin.ru>
parents:
258
diff
changeset
|
39 upstream u { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
40 server 127.0.0.1:8082; |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
41 server 127.0.0.1:8080 backup; |
269
970bb423e59f
Tests: proxy_next_upstream tests in body.t, body_chunked.t.
Maxim Dounin <mdounin@mdounin.ru>
parents:
258
diff
changeset
|
42 } |
970bb423e59f
Tests: proxy_next_upstream tests in body.t, body_chunked.t.
Maxim Dounin <mdounin@mdounin.ru>
parents:
258
diff
changeset
|
43 |
240
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
44 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
45 listen 127.0.0.1:8080; |
240
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
46 server_name localhost; |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
47 |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
48 client_header_buffer_size 1k; |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
49 |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
50 location / { |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
51 client_body_buffer_size 2k; |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
52 add_header X-Body "$request_body"; |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
53 add_header X-Body-File "$request_body_file"; |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
54 proxy_pass http://127.0.0.1:8081; |
240
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
55 } |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
56 location /b { |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
57 client_body_buffer_size 2k; |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
58 client_body_in_file_only on; |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
59 add_header X-Body "$request_body"; |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
60 add_header X-Body-File "$request_body_file"; |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
61 proxy_pass http://127.0.0.1:8081; |
240
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
62 } |
252
8b554d26eb1a
Tests: client_body_in_file_only with proxy test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
249
diff
changeset
|
63 location /small { |
8b554d26eb1a
Tests: client_body_in_file_only with proxy test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
249
diff
changeset
|
64 client_body_in_file_only on; |
271
1a6eef7ac914
Tests: test for r->request_body->buf incorrect reuse.
Maxim Dounin <mdounin@mdounin.ru>
parents:
269
diff
changeset
|
65 add_header X-Original-Uri "$request_uri"; |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
66 proxy_pass http://127.0.0.1:8080/; |
252
8b554d26eb1a
Tests: client_body_in_file_only with proxy test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
249
diff
changeset
|
67 } |
240
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
68 location /single { |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
69 client_body_in_single_buffer on; |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
70 add_header X-Body "$request_body"; |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
71 add_header X-Body-File "$request_body_file"; |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
72 proxy_pass http://127.0.0.1:8081; |
240
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
73 } |
1500
44ce08f5259f
Tests: client_max_body_size tests in body.t, body_chunked.t.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
74 location /large { |
44ce08f5259f
Tests: client_max_body_size tests in body.t, body_chunked.t.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
75 client_max_body_size 1k; |
44ce08f5259f
Tests: client_max_body_size tests in body.t, body_chunked.t.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
76 proxy_pass http://127.0.0.1:8081; |
44ce08f5259f
Tests: client_max_body_size tests in body.t, body_chunked.t.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
77 } |
240
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
78 location /discard { |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
79 return 200 "TEST\n"; |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
80 } |
269
970bb423e59f
Tests: proxy_next_upstream tests in body.t, body_chunked.t.
Maxim Dounin <mdounin@mdounin.ru>
parents:
258
diff
changeset
|
81 location /next { |
970bb423e59f
Tests: proxy_next_upstream tests in body.t, body_chunked.t.
Maxim Dounin <mdounin@mdounin.ru>
parents:
258
diff
changeset
|
82 proxy_pass http://u/; |
970bb423e59f
Tests: proxy_next_upstream tests in body.t, body_chunked.t.
Maxim Dounin <mdounin@mdounin.ru>
parents:
258
diff
changeset
|
83 } |
1539
57a92c20f974
Tests: discarded request body in error_page redirect.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1500
diff
changeset
|
84 location /redirect { |
57a92c20f974
Tests: discarded request body in error_page redirect.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1500
diff
changeset
|
85 error_page 404 http://example.com/; |
57a92c20f974
Tests: discarded request body in error_page redirect.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1500
diff
changeset
|
86 } |
240
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
87 } |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
88 |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
89 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
90 listen 127.0.0.1:8081; |
240
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
91 server_name localhost; |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
92 |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
93 location / { |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
94 return 200 "TEST\n"; |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
95 } |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
96 } |
269
970bb423e59f
Tests: proxy_next_upstream tests in body.t, body_chunked.t.
Maxim Dounin <mdounin@mdounin.ru>
parents:
258
diff
changeset
|
97 |
970bb423e59f
Tests: proxy_next_upstream tests in body.t, body_chunked.t.
Maxim Dounin <mdounin@mdounin.ru>
parents:
258
diff
changeset
|
98 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
99 listen 127.0.0.1:8082; |
269
970bb423e59f
Tests: proxy_next_upstream tests in body.t, body_chunked.t.
Maxim Dounin <mdounin@mdounin.ru>
parents:
258
diff
changeset
|
100 server_name localhost; |
970bb423e59f
Tests: proxy_next_upstream tests in body.t, body_chunked.t.
Maxim Dounin <mdounin@mdounin.ru>
parents:
258
diff
changeset
|
101 |
970bb423e59f
Tests: proxy_next_upstream tests in body.t, body_chunked.t.
Maxim Dounin <mdounin@mdounin.ru>
parents:
258
diff
changeset
|
102 location / { |
970bb423e59f
Tests: proxy_next_upstream tests in body.t, body_chunked.t.
Maxim Dounin <mdounin@mdounin.ru>
parents:
258
diff
changeset
|
103 return 444; |
970bb423e59f
Tests: proxy_next_upstream tests in body.t, body_chunked.t.
Maxim Dounin <mdounin@mdounin.ru>
parents:
258
diff
changeset
|
104 } |
970bb423e59f
Tests: proxy_next_upstream tests in body.t, body_chunked.t.
Maxim Dounin <mdounin@mdounin.ru>
parents:
258
diff
changeset
|
105 } |
240
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
106 } |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
107 |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
108 EOF |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
109 |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
110 $t->run(); |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
111 |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
112 ############################################################################### |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
113 |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
114 unlike(http_get('/'), qr/X-Body:/ms, 'no body'); |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
115 |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
116 like(http_get_body('/', '0123456789'), |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
117 qr/X-Body: 0123456789\x0d?$/ms, 'body'); |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
118 |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
119 like(http_get_body('/', '0123456789' x 128), |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
120 qr/X-Body: (0123456789){128}\x0d?$/ms, 'body in two buffers'); |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
121 |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
122 like(http_get_body('/', '0123456789' x 512), |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
123 qr/X-Body-File/ms, 'body in file'); |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
124 |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
125 like(read_body_file(http_get_body('/b', '0123456789' x 512)), |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
126 qr/^(0123456789){512}$/s, 'body in file only'); |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
127 |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
128 like(http_get_body('/single', '0123456789' x 128), |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
129 qr/X-Body: (0123456789){128}\x0d?$/ms, 'body in single buffer'); |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
130 |
1500
44ce08f5259f
Tests: client_max_body_size tests in body.t, body_chunked.t.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
131 like(http_get_body('/large', '0123456789' x 128), qr/ 413 /, 'body too large'); |
44ce08f5259f
Tests: client_max_body_size tests in body.t, body_chunked.t.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
132 |
240
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
133 # pipelined requests |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
134 |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
135 like(http_get_body('/', '0123456789', '0123456789' x 128, '0123456789' x 512, |
537
202de1d281e5
Tests: whitespace fixes.
Sergey Kandaurov <pluknet@nginx.com>
parents:
271
diff
changeset
|
136 'foobar'), qr/X-Body: foobar\x0d?$/ms, 'body pipelined'); |
240
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
137 like(http_get_body('/', '0123456789' x 128, '0123456789' x 512, '0123456789', |
537
202de1d281e5
Tests: whitespace fixes.
Sergey Kandaurov <pluknet@nginx.com>
parents:
271
diff
changeset
|
138 'foobar'), qr/X-Body: foobar\x0d?$/ms, 'body pipelined 2'); |
240
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
139 |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
140 like(http_get_body('/discard', '0123456789', '0123456789' x 128, |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
141 '0123456789' x 512, 'foobar'), qr/(TEST.*){4}/ms, |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
142 'body discard'); |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
143 like(http_get_body('/discard', '0123456789' x 128, '0123456789' x 512, |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
144 '0123456789', 'foobar'), qr/(TEST.*){4}/ms, |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
145 'body discard 2'); |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
146 |
252
8b554d26eb1a
Tests: client_body_in_file_only with proxy test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
249
diff
changeset
|
147 # proxy with file only |
8b554d26eb1a
Tests: client_body_in_file_only with proxy test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
249
diff
changeset
|
148 |
258
9f0ed4d54ae3
Tests: remove/adjust TODOs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
254
diff
changeset
|
149 like(http_get_body('/small', '0123456789'), |
252
8b554d26eb1a
Tests: client_body_in_file_only with proxy test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
249
diff
changeset
|
150 qr/X-Body: 0123456789\x0d?$/ms, 'small body in file only'); |
8b554d26eb1a
Tests: client_body_in_file_only with proxy test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
249
diff
changeset
|
151 |
271
1a6eef7ac914
Tests: test for r->request_body->buf incorrect reuse.
Maxim Dounin <mdounin@mdounin.ru>
parents:
269
diff
changeset
|
152 # proxy with file only - reuse of r->header_in |
1a6eef7ac914
Tests: test for r->request_body->buf incorrect reuse.
Maxim Dounin <mdounin@mdounin.ru>
parents:
269
diff
changeset
|
153 |
1a6eef7ac914
Tests: test for r->request_body->buf incorrect reuse.
Maxim Dounin <mdounin@mdounin.ru>
parents:
269
diff
changeset
|
154 like( |
1a6eef7ac914
Tests: test for r->request_body->buf incorrect reuse.
Maxim Dounin <mdounin@mdounin.ru>
parents:
269
diff
changeset
|
155 http( |
1a6eef7ac914
Tests: test for r->request_body->buf incorrect reuse.
Maxim Dounin <mdounin@mdounin.ru>
parents:
269
diff
changeset
|
156 'GET /small HTTP/1.0' . CRLF |
1a6eef7ac914
Tests: test for r->request_body->buf incorrect reuse.
Maxim Dounin <mdounin@mdounin.ru>
parents:
269
diff
changeset
|
157 . 'Content-Length: 10' . CRLF . CRLF |
1a6eef7ac914
Tests: test for r->request_body->buf incorrect reuse.
Maxim Dounin <mdounin@mdounin.ru>
parents:
269
diff
changeset
|
158 . '01234', |
1a6eef7ac914
Tests: test for r->request_body->buf incorrect reuse.
Maxim Dounin <mdounin@mdounin.ru>
parents:
269
diff
changeset
|
159 sleep => 0.1, |
1a6eef7ac914
Tests: test for r->request_body->buf incorrect reuse.
Maxim Dounin <mdounin@mdounin.ru>
parents:
269
diff
changeset
|
160 body => '56789' |
1a6eef7ac914
Tests: test for r->request_body->buf incorrect reuse.
Maxim Dounin <mdounin@mdounin.ru>
parents:
269
diff
changeset
|
161 ), |
1a6eef7ac914
Tests: test for r->request_body->buf incorrect reuse.
Maxim Dounin <mdounin@mdounin.ru>
parents:
269
diff
changeset
|
162 qr!X-Body: 0123456789\x0d?\x0a.*X-Original-Uri: /small!ms, |
1a6eef7ac914
Tests: test for r->request_body->buf incorrect reuse.
Maxim Dounin <mdounin@mdounin.ru>
parents:
269
diff
changeset
|
163 'small body in file only, not preread' |
1a6eef7ac914
Tests: test for r->request_body->buf incorrect reuse.
Maxim Dounin <mdounin@mdounin.ru>
parents:
269
diff
changeset
|
164 ); |
1a6eef7ac914
Tests: test for r->request_body->buf incorrect reuse.
Maxim Dounin <mdounin@mdounin.ru>
parents:
269
diff
changeset
|
165 |
269
970bb423e59f
Tests: proxy_next_upstream tests in body.t, body_chunked.t.
Maxim Dounin <mdounin@mdounin.ru>
parents:
258
diff
changeset
|
166 # proxy_next_upstream |
970bb423e59f
Tests: proxy_next_upstream tests in body.t, body_chunked.t.
Maxim Dounin <mdounin@mdounin.ru>
parents:
258
diff
changeset
|
167 |
970bb423e59f
Tests: proxy_next_upstream tests in body.t, body_chunked.t.
Maxim Dounin <mdounin@mdounin.ru>
parents:
258
diff
changeset
|
168 like(http_get_body('/next', '0123456789'), |
970bb423e59f
Tests: proxy_next_upstream tests in body.t, body_chunked.t.
Maxim Dounin <mdounin@mdounin.ru>
parents:
258
diff
changeset
|
169 qr/X-Body: 0123456789\x0d?$/ms, 'body next upstream'); |
970bb423e59f
Tests: proxy_next_upstream tests in body.t, body_chunked.t.
Maxim Dounin <mdounin@mdounin.ru>
parents:
258
diff
changeset
|
170 |
1539
57a92c20f974
Tests: discarded request body in error_page redirect.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1500
diff
changeset
|
171 # discarded request body in redirect via error_page |
57a92c20f974
Tests: discarded request body in error_page redirect.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1500
diff
changeset
|
172 |
57a92c20f974
Tests: discarded request body in error_page redirect.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1500
diff
changeset
|
173 unlike( |
57a92c20f974
Tests: discarded request body in error_page redirect.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1500
diff
changeset
|
174 http( |
57a92c20f974
Tests: discarded request body in error_page redirect.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1500
diff
changeset
|
175 'POST /redirect HTTP/1.1' . CRLF |
57a92c20f974
Tests: discarded request body in error_page redirect.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1500
diff
changeset
|
176 . 'Host: localhost' . CRLF |
57a92c20f974
Tests: discarded request body in error_page redirect.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1500
diff
changeset
|
177 . 'Content-Length: 10' . CRLF . CRLF |
57a92c20f974
Tests: discarded request body in error_page redirect.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1500
diff
changeset
|
178 . '0123456789' . |
57a92c20f974
Tests: discarded request body in error_page redirect.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1500
diff
changeset
|
179 'GET /next HTTP/1.0' . CRLF . CRLF |
57a92c20f974
Tests: discarded request body in error_page redirect.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1500
diff
changeset
|
180 ), |
57a92c20f974
Tests: discarded request body in error_page redirect.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1500
diff
changeset
|
181 qr/400 Bad Request/ms, 'redirect - discard request body' |
57a92c20f974
Tests: discarded request body in error_page redirect.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1500
diff
changeset
|
182 ); |
57a92c20f974
Tests: discarded request body in error_page redirect.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1500
diff
changeset
|
183 |
240
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
184 ############################################################################### |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
185 |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
186 sub read_body_file { |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
187 my ($r) = @_; |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
188 return '' unless $r =~ m/X-Body-File: (.*)/; |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
189 open FILE, $1 |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
190 or return "$!"; |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
191 local $/; |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
192 my $content = <FILE>; |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
193 close FILE; |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
194 return $content; |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
195 } |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
196 |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
197 sub http_get_body { |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
198 my $uri = shift; |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
199 my $last = pop; |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
200 return http( join '', (map { |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
201 my $body = $_; |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
202 "GET $uri HTTP/1.1" . CRLF |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
203 . "Host: localhost" . CRLF |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
204 . "Content-Length: " . (length $body) . CRLF . CRLF |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
205 . $body |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
206 } @_), |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
207 "GET $uri HTTP/1.1" . CRLF |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
208 . "Host: localhost" . CRLF |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
209 . "Connection: close" . CRLF |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
210 . "Content-Length: " . (length $last) . CRLF . CRLF |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
211 . $last |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
212 ); |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
213 } |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
214 |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
215 ############################################################################### |