This is an automated email from the ASF dual-hosted git repository.
spacewander pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git
The following commit(s) were added to refs/heads/master by this push:
new 639f9e0ec fix(redirect): compatible with old version data (#7584)
639f9e0ec is described below
commit 639f9e0ec60d053e7977613366fef668e9945d0c
Author: tzssangglass <[email protected]>
AuthorDate: Tue Aug 2 13:51:53 2022 +0800
fix(redirect): compatible with old version data (#7584)
---
apisix/plugins/redirect.lua | 11 +++++++----
t/plugin/redirect.t | 2 +-
t/plugin/redirect2.t | 29 +++++++++++++++++++++++++++++
3 files changed, 37 insertions(+), 5 deletions(-)
diff --git a/apisix/plugins/redirect.lua b/apisix/plugins/redirect.lua
index 5c45b7946..d858b9c86 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 246c73ce7..ec753f00b 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 ac840e6d4..24f6f8ebf 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