Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -4999,6 +4999,7 @@ The optional `status` parameter specifies the HTTP status code to be used. The f

* `301`
* `302` (default)
* `303`
* `307`

It is `302` (`ngx.HTTP_MOVED_TEMPORARILY`) by default.
Expand Down
1 change: 1 addition & 0 deletions doc/HttpLuaModule.wiki
Original file line number Diff line number Diff line change
Expand Up @@ -4164,6 +4164,7 @@ The optional <code>status</code> parameter specifies the HTTP status code to be

* <code>301</code>
* <code>302</code> (default)
* <code>303</code>
* <code>307</code>

It is <code>302</code> (<code>ngx.HTTP_MOVED_TEMPORARILY</code>) by default.
Expand Down
4 changes: 3 additions & 1 deletion src/ngx_http_lua_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,12 @@ ngx_http_lua_ngx_redirect(lua_State *L)

if (rc != NGX_HTTP_MOVED_TEMPORARILY
&& rc != NGX_HTTP_MOVED_PERMANENTLY
&& rc != NGX_HTTP_SEE_OTHER
&& rc != NGX_HTTP_TEMPORARY_REDIRECT)
{
return luaL_error(L, "only ngx.HTTP_MOVED_TEMPORARILY, "
"ngx.HTTP_MOVED_PERMANENTLY, and "
"ngx.HTTP_MOVED_PERMANENTLY, "
"ngx.HTTP_SEE_OTHER, and "
"ngx.HTTP_TEMPORARY_REDIRECT are allowed");
}

Expand Down
53 changes: 52 additions & 1 deletion t/022-redirect.t
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ GET /read
--- response_body_like: 500 Internal Server Error
--- error_code: 500
--- error_log
only ngx.HTTP_MOVED_TEMPORARILY, ngx.HTTP_MOVED_PERMANENTLY, and ngx.HTTP_TEMPORARY_REDIRECT are allowed
only ngx.HTTP_MOVED_TEMPORARILY, ngx.HTTP_MOVED_PERMANENTLY, ngx.HTTP_SEE_OTHER, and ngx.HTTP_TEMPORARY_REDIRECT are allowed



Expand Down Expand Up @@ -218,3 +218,54 @@ GET /read
Location: http://agentzh.org/foo?a=b&c=d
--- response_body_like: 307 Temporary Redirect
--- error_code: 307



=== TEST 12: explicit 303
--- config
location /read {
content_by_lua_block {
ngx.redirect("http://agentzh.org/foo", ngx.HTTP_SEE_OTHER);
ngx.say("hi")
}
}
--- request
GET /read
--- response_headers
Location: http://agentzh.org/foo
--- response_body_like: 303 See Other
--- error_code: 303



=== TEST 13: explicit 303 with args
--- config
location /read {
content_by_lua_block {
ngx.redirect("http://agentzh.org/foo?a=b&c=d", ngx.HTTP_SEE_OTHER);
ngx.say("hi")
}
}
--- request
GET /read
--- response_headers
Location: http://agentzh.org/foo?a=b&c=d
--- response_body_like: 303 See Other
--- error_code: 303



=== TEST 14: explicit 303
--- config
location /read {
content_by_lua_block {
ngx.redirect("http://agentzh.org/foo?a=b&c=d", 303);
ngx.say("hi")
}
}
--- request
GET /read
--- response_headers
Location: http://agentzh.org/foo?a=b&c=d
--- response_body_like: 303 See Other
--- error_code: 303