diff --git a/apisix/plugins/redirect.lua b/apisix/plugins/redirect.lua index 5c45b7946dcb..d858b9c86df9 100644 --- a/apisix/plugins/redirect.lua +++ b/apisix/plugins/redirect.lua @@ -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"}} } } @@ -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 @@ -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 diff --git a/t/plugin/redirect.t b/t/plugin/redirect.t index 246c73ce7cad..ec753f00ba2f 100644 --- a/t/plugin/redirect.t +++ b/t/plugin/redirect.t @@ -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] diff --git a/t/plugin/redirect2.t b/t/plugin/redirect2.t index ac840e6d4274..24f6f8ebf3fb 100644 --- a/t/plugin/redirect2.t +++ b/t/plugin/redirect2.t @@ -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 +--- 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