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#repeat_each(1);
11
12plan tests => blocks() * repeat_each() * 3;
13
14#no_diff();
15#no_long_string();
16
17run_tests();
18
19__DATA__
20
21=== TEST 1: default 302
22--- config
23    location /read {
24        access_by_lua '
25            ngx.redirect("http://www.taobao.com/foo");
26            ngx.say("hi")
27        ';
28        content_by_lua 'return';
29    }
30--- request
31GET /read
32--- response_headers
33Location: http://www.taobao.com/foo
34--- response_body_like: 302 Found
35--- error_code: 302
36
37
38
39=== TEST 2: explicit 302
40--- config
41    location /read {
42        access_by_lua '
43            ngx.redirect("http://www.taobao.com/foo", ngx.HTTP_MOVED_TEMPORARILY);
44            ngx.say("hi")
45        ';
46        content_by_lua 'return';
47    }
48--- request
49GET /read
50--- response_headers
51Location: http://www.taobao.com/foo
52--- response_body_like: 302 Found
53--- error_code: 302
54
55
56
57=== TEST 3: explicit 301
58--- config
59    location /read {
60        access_by_lua '
61            ngx.redirect("http://www.taobao.com/foo", ngx.HTTP_MOVED_PERMANENTLY);
62            ngx.say("hi")
63        ';
64        content_by_lua 'return';
65    }
66--- request
67GET /read
68--- response_headers
69Location: http://www.taobao.com/foo
70--- response_body_like: 301 Moved Permanently
71--- error_code: 301
72
73
74
75=== TEST 4: bad rc
76--- config
77    location /read {
78        access_by_lua '
79            ngx.redirect("http://www.taobao.com/foo", 404);
80            ngx.say("hi")
81        ';
82        content_by_lua 'return';
83    }
84--- request
85GET /read
86--- response_headers
87!Location
88--- response_body_like: 500 Internal Server Error
89--- error_code: 500
90
91
92
93=== TEST 5: no args
94--- config
95    location /read {
96        access_by_lua '
97            ngx.redirect()
98            ngx.say("hi")
99        ';
100        content_by_lua 'return';
101    }
102--- request
103GET /read
104--- response_headers
105!Location
106--- response_body_like: 500 Internal Server Error
107--- error_code: 500
108
109
110
111=== TEST 6: relative uri
112--- config
113    location /read {
114        access_by_lua '
115            ngx.redirect("/foo")
116            ngx.say("hi")
117        ';
118        content_by_lua 'return';
119    }
120--- request
121GET /read
122--- raw_response_headers_like: Location: /foo\r\n
123--- response_body_like: 302 Found
124--- error_code: 302
125