Skip to content
Merged
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
11 changes: 7 additions & 4 deletions apisix/plugins/redirect.lua
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,12 @@ local schema = {
},
http_to_https = {type = "boolean"},
encode_uri = {type = "boolean", default = false},
append_query_string = {type = "boolean"},
append_query_string = {type = "boolean", default = false},
},
oneOf = {
{required = {"uri"}},
{required = {"regex_uri"}},
{required = {"http_to_https"}, ["not"] = {
required = {"append_query_string"}
}}
{required = {"http_to_https"}}
}
}

Expand Down Expand Up @@ -103,6 +101,7 @@ end

function _M.check_schema(conf)
local ok, err = core.schema.check(schema, conf)

if not ok then
return false, err
end
Expand All @@ -117,6 +116,10 @@ function _M.check_schema(conf)
end
end

if conf.http_to_https and conf.append_query_string then
return false, "only one of `http_to_https` and `append_query_string` can be configured."
end

return true
end

Expand Down
2 changes: 1 addition & 1 deletion t/plugin/redirect.t
Original file line number Diff line number Diff line change
Expand Up @@ -1146,6 +1146,6 @@ Location: https://foo.com:9443/hello
GET /t
--- error_code: 400
--- response_body eval
qr/error_msg":"failed to check the configuration of plugin redirect err: value should match only one schema, but matches none/
qr/error_msg":"failed to check the configuration of plugin redirect err: only one of `http_to_https` and `append_query_string` can be configured."/
--- no_error_log
[error]
29 changes: 29 additions & 0 deletions t/plugin/redirect2.t
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,32 @@ GET /test/hello?o=apache
--- response_headers
Location: http://test.com/hello?q=apisix&o=apache
--- error_code: 302



=== TEST 3: compatible with old version configuration
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also test the case that http_to_https is true and append_query_string is also true.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--- config
location /t {
content_by_lua_block {
local t = require("lib.test_admin").test
local code, body = t('/apisix/admin/routes/1',
ngx.HTTP_PUT,
[[{
"uri": "/hello",
"host": "foo.com",
"plugins": {
"redirect": {
"http_to_https": true,
"append_query_string": false
}
}
}]]
)
if code >= 300 then
ngx.status = code
end
ngx.say(body)
}
}
--- response_body
passed