1
# vim:set ft= ts=4 sw=4 et fdm=marker:
3
use Test::Nginx::Socket;
5
#worker_connections(1014);
6
#master_process_enabled(1);
12
plan tests => repeat_each() * (blocks() * 2);
14
$ENV{TEST_NGINX_MEMCACHED_PORT} ||= 11211;
25
default_type 'foo/bar';
26
echo $echo_request_method;
31
res = ngx.location.capture("/other",
32
{ method = ngx.HTTP_DELETE });
36
content_by_lua 'ngx.exit(ngx.OK)';
45
=== TEST 2: DELETE (proxy method)
48
default_type 'foo/bar';
49
echo $echo_request_method;
53
proxy_pass http://127.0.0.1:$server_port/other;
58
res = ngx.location.capture("/foo",
59
{ method = ngx.HTTP_DELETE });
64
content_by_lua 'ngx.exit(ngx.OK)';
73
=== TEST 3: POST (nobody, proxy method)
76
default_type 'foo/bar';
77
echo $echo_request_method;
81
proxy_pass http://127.0.0.1:$server_port/other;
86
res = ngx.location.capture("/foo",
87
{ method = ngx.HTTP_POST });
91
content_by_lua 'ngx.exit(ngx.OK)';
103
default_type 'foo/bar';
104
echo $echo_request_method;
109
res = ngx.location.capture("/other",
110
{ method = ngx.HTTP_HEAD });
114
content_by_lua 'ngx.exit(ngx.OK)';
123
=== TEST 5: explicit GET
126
default_type 'foo/bar';
127
echo $echo_request_method;
131
proxy_pass http://127.0.0.1:$server_port/other;
136
res = ngx.location.capture("/foo",
137
{ method = ngx.HTTP_GET });
141
content_by_lua 'ngx.exit(ngx.OK)';
150
=== TEST 6: implicit GET
153
default_type 'foo/bar';
154
echo $echo_request_method;
158
proxy_pass http://127.0.0.1:$server_port/other;
163
res = ngx.location.capture("/foo")
167
content_by_lua 'ngx.exit(ngx.OK)';
176
=== TEST 7: implicit GET (empty option table)
179
default_type 'foo/bar';
180
echo $echo_request_method;
184
proxy_pass http://127.0.0.1:$server_port/other;
189
res = ngx.location.capture("/foo", {})
193
content_by_lua 'ngx.exit(ngx.OK)';
202
=== TEST 8: PUT (nobody, proxy method)
205
default_type 'foo/bar';
206
echo_read_request_body;
208
echo $echo_request_method;
213
proxy_pass http://127.0.0.1:$server_port/other;
218
res = ngx.location.capture("/foo",
219
{ method = ngx.HTTP_PUT, body = "hello" });
223
content_by_lua 'ngx.exit(ngx.OK)';
227
--- response_body chomp
233
=== TEST 9: PUT (nobody, no proxy method)
236
default_type 'foo/bar';
237
#echo_read_request_body;
239
echo $echo_request_method;
240
#echo $echo_request_body;
246
res = ngx.location.capture("/other",
247
{ method = ngx.HTTP_PUT, body = "hello" });
251
content_by_lua 'ngx.exit(ngx.OK)';
255
--- response_body chomp
261
=== TEST 10: PUT (nobody, no proxy method)
264
default_type 'foo/bar';
265
#echo_read_request_body;
267
echo $echo_request_method;
268
#echo $echo_request_body;
270
#echo "[$http_content_length]";
275
echo $echo_request_method;
276
echo -n "[$http_content_length]";
281
res = ngx.location.capture("/other",
282
{ method = ngx.HTTP_PUT, body = "hello" });
286
res = ngx.location.capture("/foo")
290
content_by_lua 'ngx.exit(ngx.OK)';
302
=== TEST 11: POST (with body, proxy method)
305
default_type 'foo/bar';
306
echo_read_request_body;
308
echo $echo_request_method;
313
proxy_pass http://127.0.0.1:$server_port/other;
318
res = ngx.location.capture("/foo",
319
{ method = ngx.HTTP_POST, body = "hello" });
323
content_by_lua 'ngx.exit(ngx.OK)';
327
--- response_body chomp
333
=== TEST 12: POST (with body, memc method)
336
set $memc_cmd flush_all;
337
memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
341
set $memc_key $echo_request_uri;
342
set $memc_exptime 600;
343
memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
348
ngx.location.capture("/flush");
350
res = ngx.location.capture("/memc");
351
ngx.say("GET: " .. res.status);
353
res = ngx.location.capture("/memc",
354
{ method = ngx.HTTP_PUT, body = "hello" });
355
ngx.say("PUT: " .. res.status);
357
res = ngx.location.capture("/memc");
358
ngx.say("cached: " .. res.body);
361
content_by_lua 'ngx.exit(ngx.OK)';
372
=== TEST 13: POST (with body, memc method)
375
set $memc_cmd flush_all;
376
memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
381
set $memc_key $echo_request_uri;
382
set $memc_exptime 600;
383
memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
388
ngx.location.capture("/flush",
389
{ share_all_vars = true });
391
res = ngx.location.capture("/memc",
392
{ share_all_vars = true });
393
ngx.say("GET: " .. res.status);
395
res = ngx.location.capture("/memc",
396
{ method = ngx.HTTP_PUT, body = "hello", share_all_vars = true });
397
ngx.say("PUT: " .. res.status);
399
res = ngx.location.capture("/memc", { share_all_vars = true });
400
ngx.say("cached: " .. res.body);
403
content_by_lua 'ngx.exit(ngx.OK)';
414
=== TEST 14: emtpy args option table
422
res = ngx.location.capture("/foo",
426
content_by_lua 'ngx.exit(ngx.OK)';
430
--- response_body eval: "\n"
434
=== TEST 15: non-empty args option table (1 pair)
442
res = ngx.location.capture("/foo",
443
{ args = { ["fo="] = "=>" } })
446
content_by_lua 'ngx.exit(ngx.OK)';
455
=== TEST 16: non-empty args option table (2 pairs)
463
res = ngx.location.capture("/foo",
464
{ args = { ["fo="] = "=>",
468
content_by_lua 'ngx.exit(ngx.OK)';
477
=== TEST 17: non-empty args option table (2 pairs, no special chars)
485
res = ngx.location.capture("/foo",
490
content_by_lua 'ngx.exit(ngx.OK)';
499
=== TEST 18: non-empty args option table (number key)
507
res = ngx.location.capture("/foo",
508
{ args = { [57] = "hi" } })
511
content_by_lua 'ngx.exit(ngx.OK)';
515
--- response_body_like: 500 Internal Server Error
520
=== TEST 19: non-empty args option table (plain arrays)
528
res = ngx.location.capture("/foo",
532
content_by_lua 'ngx.exit(ngx.OK)';
536
--- response_body_like: 500 Internal Server Error
541
=== TEST 20: more args
549
res = ngx.location.capture("/foo?a=3",
550
{ args = { b = 4 } })
553
content_by_lua 'ngx.exit(ngx.OK)';
562
=== TEST 21: more args
570
res = ngx.location.capture("/foo?a=3",
574
content_by_lua 'ngx.exit(ngx.OK)';