1# vim:set ft= ts=4 sw=4 et fdm=marker: 2 3use Test::Nginx::Socket::Lua; 4 5#worker_connections(1014); 6#master_process_enabled(1); 7#log_level('warn'); 8 9repeat_each(2); 10 11plan tests => repeat_each() * (blocks() * 2 + 19); 12 13#no_diff(); 14#no_long_string(); 15#master_on(); 16#workers(2); 17run_tests(); 18 19__DATA__ 20 21=== TEST 1: read buffered body 22--- config 23 location = /test { 24 access_by_lua ' 25 ngx.req.read_body() 26 ngx.say(ngx.var.request_body) 27 '; 28 content_by_lua return; 29 } 30--- request 31POST /test 32hello, world 33--- response_body 34hello, world 35 36 37 38=== TEST 2: read buffered body (timed out) 39--- config 40 client_body_timeout 1ms; 41 location = /test { 42 access_by_lua ' 43 ngx.req.read_body() 44 ngx.say(ngx.var.request_body) 45 '; 46 content_by_lua return; 47 } 48--- raw_request eval 49"POST /test HTTP/1.1\r 50Host: localhost\r 51Content-Length: 100\r 52Connection: close\r 53\r 54hello, world" 55--- response_body: 56--- error_code_like: ^(?:500)?$ 57 58 59 60=== TEST 3: read buffered body and then subrequest 61--- config 62 location /foo { 63 echo -n foo; 64 } 65 location = /test { 66 access_by_lua ' 67 ngx.req.read_body() 68 local res = ngx.location.capture("/foo"); 69 ngx.say(ngx.var.request_body) 70 ngx.say("sub: ", res.body) 71 '; 72 content_by_lua return; 73 } 74--- request 75POST /test 76hello, world 77--- response_body 78hello, world 79sub: foo 80 81 82 83=== TEST 4: first subrequest and then read buffered body 84--- config 85 location /foo { 86 echo -n foo; 87 } 88 location = /test { 89 access_by_lua ' 90 local res = ngx.location.capture("/foo"); 91 ngx.req.read_body() 92 ngx.say(ngx.var.request_body) 93 ngx.say("sub: ", res.body) 94 '; 95 content_by_lua return; 96 } 97--- request 98POST /test 99hello, world 100--- response_body 101hello, world 102sub: foo 103 104 105 106=== TEST 5: failed to write 100 continue 107--- config 108 location = /test { 109 access_by_lua ' 110 ngx.req.read_body() 111 ngx.say(ngx.var.request_body) 112 ngx.exit(200) 113 '; 114 } 115--- request 116POST /test 117hello, world 118--- more_headers 119Expect: 100-Continue 120--- ignore_response 121--- no_error_log 122[alert] 123[error] 124http finalize request: 500, "/test?" a:1, c:0 125 126 127 128=== TEST 6: not discard body (exit 200) 129--- config 130 location = /foo { 131 access_by_lua ' 132 -- ngx.req.discard_body() 133 ngx.say("body: ", ngx.var.request_body) 134 ngx.exit(200) 135 '; 136 } 137 location = /bar { 138 content_by_lua ' 139 ngx.req.read_body() 140 ngx.say("body: ", ngx.var.request_body) 141 '; 142 } 143--- pipelined_requests eval 144["POST /foo 145hello, world", 146"POST /bar 147hiya, world"] 148--- response_body eval 149["body: nil\n", 150"body: hiya, world\n", 151] 152--- error_code eval 153[200, 200] 154--- no_error_log 155[error] 156[alert] 157 158 159 160=== TEST 7: not discard body (exit 201) 161--- config 162 location = /foo { 163 access_by_lua ' 164 -- ngx.req.discard_body() 165 ngx.say("body: ", ngx.var.request_body) 166 ngx.exit(201) 167 '; 168 } 169 location = /bar { 170 content_by_lua ' 171 ngx.req.read_body() 172 ngx.say("body: ", ngx.var.request_body) 173 '; 174 } 175--- pipelined_requests eval 176["POST /foo 177hello, world", 178"POST /bar 179hiya, world"] 180--- response_body eval 181["body: nil\n", 182"body: hiya, world\n", 183] 184--- error_code eval 185[200, 200] 186--- no_error_log 187[error] 188[alert] 189 190 191 192=== TEST 8: not discard body (exit 302) 193--- config 194 location = /foo { 195 access_by_lua ' 196 -- ngx.req.discard_body() 197 -- ngx.say("body: ", ngx.var.request_body) 198 ngx.redirect("/blah") 199 '; 200 } 201 location = /bar { 202 content_by_lua ' 203 ngx.req.read_body() 204 ngx.say("body: ", ngx.var.request_body) 205 '; 206 } 207--- pipelined_requests eval 208["POST /foo 209hello, world", 210"POST /bar 211hiya, world"] 212--- response_body eval 213[qr/302 Found/, 214"body: hiya, world\n", 215] 216--- error_code eval 217[302, 200] 218--- no_error_log 219[error] 220[alert] 221