From e01f4f13d567bea8a2641351a9954ce4370a023c Mon Sep 17 00:00:00 2001 From: vyvyan2010 <375636559@qq.com> Date: Mon, 11 Jul 2022 01:47:21 -0700 Subject: [PATCH 1/3] fix: the query string is repeated twice when enable http-to-https and append-query-string (#7394) --- apisix/plugins/redirect.lua | 31 +++++++++--- docs/en/latest/plugins/redirect.md | 3 +- docs/zh/latest/plugins/redirect.md | 5 +- t/plugin/redirect.t | 79 +++++++++++++++++++++--------- 4 files changed, 87 insertions(+), 31 deletions(-) diff --git a/apisix/plugins/redirect.lua b/apisix/plugins/redirect.lua index 6c9a99a1575c..23226f9030f5 100644 --- a/apisix/plugins/redirect.lua +++ b/apisix/plugins/redirect.lua @@ -55,13 +55,32 @@ local schema = { }, http_to_https = {type = "boolean"}, encode_uri = {type = "boolean", default = false}, - append_query_string = {type = "boolean", default = false}, + append_query_string = {type = "boolean"}, + }, + allOf = { + { + oneOf = { + {required = {"uri"}}, + {required = {"regex_uri"}}, + {required = {"http_to_https"}}, + }, + }, + -- append_query_string and http_to_https are exclusive + { + oneOf = { + {required = {"append_query_string"}}, + {required = {"http_to_https"}}, + { + ["not"] = { + anyOf = { + {required = {"append_query_string"}}, + {required = {"http_to_https"}}, + }, + }, + }, + }, + }, }, - oneOf = { - {required = {"uri"}}, - {required = {"regex_uri"}}, - {required = {"http_to_https"}} - } } diff --git a/docs/en/latest/plugins/redirect.md b/docs/en/latest/plugins/redirect.md index 8a7a034bc934..75828aa8404a 100644 --- a/docs/en/latest/plugins/redirect.md +++ b/docs/en/latest/plugins/redirect.md @@ -34,7 +34,7 @@ The `redirect` Plugin can be used to configure redirects. | Name | Type | Required | Default | Valid values | Description | |---------------------|---------------|----------|---------|--------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| http_to_https | boolean | False | false | | When set to `true` and the request is HTTP, it will be redirected to HTTPS with the same URI with a 301 status code. | +| http_to_https | boolean | False | false | | When set to `true` and the request is HTTP, it will be redirected to HTTPS with the same URI with a 301 status code, contains the query string. | | uri | string | False | | | URI to redirect to. Can contain Nginx variables. For example, `/test/index.html`, `$uri/index.html`, `${uri}/index.html`. If you refer to a variable name that doesn't exist, instead of throwing an error, it will treat it as an empty variable. | | regex_uri | array[string] | False | | | Match the URL from client with a regular expression and redirect. If it doesn't match, the request will be forwarded to the Upstream. Only either of `uri` or `regex_uri` can be used at a time. For example, [" ^/iresty/(.*)/(.*)/(.*)", "/$1-$2-$3"], where the first element is the regular expression to match and the second element is the URI to redirect to. | | ret_code | integer | False | 302 | [200, ...] | HTTP response code. | @@ -44,6 +44,7 @@ The `redirect` Plugin can be used to configure redirects. :::note Only one of `http_to_https`, `uri` and `regex_uri` can be configured. +Only one of `http_to_https` and `append_query_string` can be configured. * When enabling `http_to_https`, the ports in the redirect URL will pick a value in the following order (in descending order of priority) * Read `plugin_attr.redirect.https_port` from the configuration file (`conf/config.yaml`). diff --git a/docs/zh/latest/plugins/redirect.md b/docs/zh/latest/plugins/redirect.md index c40726a16887..72b3dcb7d1dd 100644 --- a/docs/zh/latest/plugins/redirect.md +++ b/docs/zh/latest/plugins/redirect.md @@ -34,16 +34,17 @@ description: 本文介绍了关于 Apache APISIX `redirect` 插件的基本信 | 名称 | 类型 | 必选项 | 默认值 | 有效值 | 描述 | |---------------------|---------------|-----|-------|--------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| http_to_https | boolean | 否 | false | [true,false] | 当设置为 `true` 并且请求是 HTTP 时,它将被重定向具有相同 URI 和 301 状态码的 HTTPS。 | +| http_to_https | boolean | 否 | false | [true,false] | 当设置为 `true` 并且请求是 HTTP 时,它将被重定向具有相同 URI 和 301 状态码的 HTTPS,包含查询字符串。 | | uri | string | 否 | | | 要重定向到的 URI,可以包含 NGINX 变量。例如:`/test/index.htm`, `$uri/index.html`,`${uri}/index.html`。如果你引入了一个不存在的变量,它不会报错,而是将其视为一个空变量。 | | regex_uri | array[string] | 否 | | | 将来自客户端的 URL 与正则表达式匹配并重定向。当匹配成功后使用模板替换发送重定向到客户端,如果未匹配成功会将客户端请求的 URI 转发至上游。 和 `regex_uri` 不可以同时存在。例如:["^/iresty/(.)/(.)/(.*)","/$1-$2-$3"] 第一个元素代表匹配来自客户端请求的 URI 正则表达式,第二个元素代表匹配成功后发送重定向到客户端的 URI 模板。 | | ret_code | integer | 否 | 302 | [200, ...] | HTTP 响应码 | -| encode_uri | boolean | 否 | false | [true,false] | 当设置为 `true` 时,对返回的 `Location` Header 按照 [RFC3986](https://datatracker.ietf.org/doc/html/rfc3986)的编码格式进行编码。 | +| encode_uri | boolean | 否 | false | [true,false] | 当设置为 `true` 时,对返回的 `Location` Header 按照 [RFC3986](https://datatracker.ietf.org/doc/html/rfc3986) 的编码格式进行编码。 | | append_query_string | boolean | 否 | false | [true,false] | 当设置为 `true` 时,将原始请求中的查询字符串添加到 `Location` Header。如果已配置 `uri` 或 `regex_uri` 已经包含查询字符串,则请求中的查询字符串将附加一个`&`。如果你已经处理过查询字符串(例如,使用 NGINX 变量 `$request_uri`),请不要再使用该参数以避免重复。 | :::note `http_to_https`、`uri` 和 `regex_uri` 只能配置其中一个属性。 +`http_to_https`、和 `append_query_string` 只能配置其中一个属性。 * 当开启 `http_to_https` 时,重定向 URL 中的端口将按如下顺序选取一个值(按优先级从高到低排列) * 从配置文件(`conf/config.yaml`)中读取 `plugin_attr.redirect.https_port`。 diff --git a/t/plugin/redirect.t b/t/plugin/redirect.t index 3b8d87afd787..4c3933602bb0 100644 --- a/t/plugin/redirect.t +++ b/t/plugin/redirect.t @@ -582,13 +582,48 @@ 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 both schemas 1 and 3/ +qr/error_msg":"failed to check the configuration of plugin redirect err: allOf 1 failed: value should match only one schema, but matches both schemas 1 and 3/ --- no_error_log [error] -=== TEST 26: enable http_to_https with upstream +=== TEST 26: wrong configure, enable http_to_https with append_query_string +--- 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": true + } + } + }]] + ) + + if code >= 300 then + ngx.status = code + end + ngx.say(body) + } + } +--- request +GET /t +--- error_code: 400 +--- response_body eval +qr/error_msg":"failed to check the configuration of plugin redirect err: allOf 2 failed: value should match only one schema, but matches both schemas 1 and 2/ +--- no_error_log +[error] + + + +=== TEST 27: enable http_to_https with upstream --- config location /t { content_by_lua_block { @@ -627,7 +662,7 @@ passed -=== TEST 27: redirect +=== TEST 28: redirect --- request GET /hello --- more_headers @@ -638,7 +673,7 @@ Location: https://test.com:9443/hello -=== TEST 28: set ssl(sni: test.com) +=== TEST 29: set ssl(sni: test.com) --- config location /t { content_by_lua_block { @@ -669,7 +704,7 @@ passed -=== TEST 29: client https request +=== TEST 30: client https request --- config listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl; @@ -743,7 +778,7 @@ close: 1 nil} -=== TEST 30: add plugin with new uri: /test/add +=== TEST 31: add plugin with new uri: /test/add --- config location /t { content_by_lua_block { @@ -778,7 +813,7 @@ passed -=== TEST 31: http to https post redirect +=== TEST 32: http to https post redirect --- request POST /hello-https --- more_headers @@ -791,7 +826,7 @@ Location: https://test.com:9443/hello-https -=== TEST 32: http to https get redirect +=== TEST 33: http to https get redirect --- request GET /hello-https --- more_headers @@ -804,7 +839,7 @@ Location: https://test.com:9443/hello-https -=== TEST 33: http to https head redirect +=== TEST 34: http to https head redirect --- request HEAD /hello-https --- more_headers @@ -817,7 +852,7 @@ Location: https://test.com:9443/hello-https -=== TEST 34: add plugin with new regex_uri: /test/1 redirect to http://test.com/1 +=== TEST 35: add plugin with new regex_uri: /test/1 redirect to http://test.com/1 --- config location /t { content_by_lua_block { @@ -856,7 +891,7 @@ passed -=== TEST 35: regex_uri redirect +=== TEST 36: regex_uri redirect --- request GET /test/1 --- response_headers @@ -867,7 +902,7 @@ Location: http://test.com/1 -=== TEST 36: regex_uri not match, get response from upstream +=== TEST 37: regex_uri not match, get response from upstream --- request GET /hello --- error_code: 200 @@ -878,7 +913,7 @@ hello world -=== TEST 37: add plugin with new regex_uri: encode_uri = true +=== TEST 38: add plugin with new regex_uri: encode_uri = true --- config location /t { content_by_lua_block { @@ -918,7 +953,7 @@ passed -=== TEST 38: regex_uri redirect with special characters +=== TEST 39: regex_uri redirect with special characters --- request GET /test/with%20space --- error_code: 200 @@ -930,7 +965,7 @@ Location: http://test.com/with%20space -=== TEST 39: add plugin with new uri: encode_uri = true +=== TEST 40: add plugin with new uri: encode_uri = true --- config location /t { content_by_lua_block { @@ -964,7 +999,7 @@ passed -=== TEST 40: redirect with special characters +=== TEST 41: redirect with special characters --- request GET /hello/with%20space --- response_headers @@ -975,7 +1010,7 @@ Location: /hello/with%20space -=== TEST 41: add plugin with new uri: $uri (append_query_string = true) +=== TEST 42: add plugin with new uri: $uri (append_query_string = true) --- config location /t { content_by_lua_block { @@ -1009,7 +1044,7 @@ passed -=== TEST 42: redirect +=== TEST 43: redirect --- request GET /hello?name=json --- response_headers @@ -1020,7 +1055,7 @@ Location: /hello?name=json -=== TEST 43: add plugin with new uri: $uri?type=string (append_query_string = true) +=== TEST 44: add plugin with new uri: $uri?type=string (append_query_string = true) --- config location /t { content_by_lua_block { @@ -1054,7 +1089,7 @@ passed -=== TEST 44: redirect +=== TEST 45: redirect --- request GET /hello?name=json --- response_headers @@ -1065,7 +1100,7 @@ Location: /hello?type=string&name=json -=== TEST 45: enable http_to_https (pass X-Forwarded-Proto) +=== TEST 46: enable http_to_https (pass X-Forwarded-Proto) --- config location /t { content_by_lua_block { @@ -1105,7 +1140,7 @@ passed -=== TEST 46: enable http_to_https (pass X-Forwarded-Proto) +=== TEST 47: enable http_to_https (pass X-Forwarded-Proto) --- request GET /hello --- more_headers From a7f10c21fcacac1001988b13f4059feda4e1883e Mon Sep 17 00:00:00 2001 From: vyvyan2010 <375636559@qq.com> Date: Mon, 11 Jul 2022 03:56:31 -0700 Subject: [PATCH 2/3] tweak: minor changes. --- docs/en/latest/plugins/redirect.md | 7 +- docs/zh/latest/plugins/redirect.md | 7 +- t/plugin/redirect.t | 112 ++++++++++++++--------------- 3 files changed, 62 insertions(+), 64 deletions(-) diff --git a/docs/en/latest/plugins/redirect.md b/docs/en/latest/plugins/redirect.md index 75828aa8404a..e772894a047c 100644 --- a/docs/en/latest/plugins/redirect.md +++ b/docs/en/latest/plugins/redirect.md @@ -34,7 +34,7 @@ The `redirect` Plugin can be used to configure redirects. | Name | Type | Required | Default | Valid values | Description | |---------------------|---------------|----------|---------|--------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| http_to_https | boolean | False | false | | When set to `true` and the request is HTTP, it will be redirected to HTTPS with the same URI with a 301 status code, contains the query string. | +| http_to_https | boolean | False | false | | When set to `true` and the request is HTTP, it will be redirected to HTTPS with the same URI with a 301 status code. Note the querystring from the raw URI will also be contained in the Location header. | | uri | string | False | | | URI to redirect to. Can contain Nginx variables. For example, `/test/index.html`, `$uri/index.html`, `${uri}/index.html`. If you refer to a variable name that doesn't exist, instead of throwing an error, it will treat it as an empty variable. | | regex_uri | array[string] | False | | | Match the URL from client with a regular expression and redirect. If it doesn't match, the request will be forwarded to the Upstream. Only either of `uri` or `regex_uri` can be used at a time. For example, [" ^/iresty/(.*)/(.*)/(.*)", "/$1-$2-$3"], where the first element is the regular expression to match and the second element is the URI to redirect to. | | ret_code | integer | False | 302 | [200, ...] | HTTP response code. | @@ -43,9 +43,8 @@ The `redirect` Plugin can be used to configure redirects. :::note -Only one of `http_to_https`, `uri` and `regex_uri` can be configured. -Only one of `http_to_https` and `append_query_string` can be configured. - +* Only one of `http_to_https`, `uri` and `regex_uri` can be configured. +* Only one of `http_to_https` and `append_query_string` can be configured. * When enabling `http_to_https`, the ports in the redirect URL will pick a value in the following order (in descending order of priority) * Read `plugin_attr.redirect.https_port` from the configuration file (`conf/config.yaml`). * If `apisix.ssl` is enabled, read `apisix.ssl.listen_port` first, and if it does not exist, read `apisix.ssl.listen` and select a port randomly from it. diff --git a/docs/zh/latest/plugins/redirect.md b/docs/zh/latest/plugins/redirect.md index 72b3dcb7d1dd..dcb05411cded 100644 --- a/docs/zh/latest/plugins/redirect.md +++ b/docs/zh/latest/plugins/redirect.md @@ -34,7 +34,7 @@ description: 本文介绍了关于 Apache APISIX `redirect` 插件的基本信 | 名称 | 类型 | 必选项 | 默认值 | 有效值 | 描述 | |---------------------|---------------|-----|-------|--------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| http_to_https | boolean | 否 | false | [true,false] | 当设置为 `true` 并且请求是 HTTP 时,它将被重定向具有相同 URI 和 301 状态码的 HTTPS,包含查询字符串。 | +| http_to_https | boolean | 否 | false | [true,false] | 当设置为 `true` 并且请求是 HTTP 时,它将被重定向具有相同 URI 和 301 状态码的 HTTPS,原 URI 的查询字符串也将包含在 Location 头中。 | | uri | string | 否 | | | 要重定向到的 URI,可以包含 NGINX 变量。例如:`/test/index.htm`, `$uri/index.html`,`${uri}/index.html`。如果你引入了一个不存在的变量,它不会报错,而是将其视为一个空变量。 | | regex_uri | array[string] | 否 | | | 将来自客户端的 URL 与正则表达式匹配并重定向。当匹配成功后使用模板替换发送重定向到客户端,如果未匹配成功会将客户端请求的 URI 转发至上游。 和 `regex_uri` 不可以同时存在。例如:["^/iresty/(.)/(.)/(.*)","/$1-$2-$3"] 第一个元素代表匹配来自客户端请求的 URI 正则表达式,第二个元素代表匹配成功后发送重定向到客户端的 URI 模板。 | | ret_code | integer | 否 | 302 | [200, ...] | HTTP 响应码 | @@ -43,9 +43,8 @@ description: 本文介绍了关于 Apache APISIX `redirect` 插件的基本信 :::note -`http_to_https`、`uri` 和 `regex_uri` 只能配置其中一个属性。 -`http_to_https`、和 `append_query_string` 只能配置其中一个属性。 - +* `http_to_https`、`uri` 和 `regex_uri` 只能配置其中一个属性。 +* `http_to_https`、和 `append_query_string` 只能配置其中一个属性。 * 当开启 `http_to_https` 时,重定向 URL 中的端口将按如下顺序选取一个值(按优先级从高到低排列) * 从配置文件(`conf/config.yaml`)中读取 `plugin_attr.redirect.https_port`。 * 如果 `apisix.ssl` 处于开启状态,先读取 `apisix.ssl.listen_port`,如果没有,再读取 `apisix.ssl.listen` 并从中随机选一个 `port`。 diff --git a/t/plugin/redirect.t b/t/plugin/redirect.t index 4c3933602bb0..25b08078eff3 100644 --- a/t/plugin/redirect.t +++ b/t/plugin/redirect.t @@ -588,42 +588,7 @@ qr/error_msg":"failed to check the configuration of plugin redirect err: allOf 1 -=== TEST 26: wrong configure, enable http_to_https with append_query_string ---- 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": true - } - } - }]] - ) - - if code >= 300 then - ngx.status = code - end - ngx.say(body) - } - } ---- request -GET /t ---- error_code: 400 ---- response_body eval -qr/error_msg":"failed to check the configuration of plugin redirect err: allOf 2 failed: value should match only one schema, but matches both schemas 1 and 2/ ---- no_error_log -[error] - - - -=== TEST 27: enable http_to_https with upstream +=== TEST 26: enable http_to_https with upstream --- config location /t { content_by_lua_block { @@ -662,7 +627,7 @@ passed -=== TEST 28: redirect +=== TEST 27: redirect --- request GET /hello --- more_headers @@ -673,7 +638,7 @@ Location: https://test.com:9443/hello -=== TEST 29: set ssl(sni: test.com) +=== TEST 28: set ssl(sni: test.com) --- config location /t { content_by_lua_block { @@ -704,7 +669,7 @@ passed -=== TEST 30: client https request +=== TEST 29: client https request --- config listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl; @@ -778,7 +743,7 @@ close: 1 nil} -=== TEST 31: add plugin with new uri: /test/add +=== TEST 30: add plugin with new uri: /test/add --- config location /t { content_by_lua_block { @@ -813,7 +778,7 @@ passed -=== TEST 32: http to https post redirect +=== TEST 31: http to https post redirect --- request POST /hello-https --- more_headers @@ -826,7 +791,7 @@ Location: https://test.com:9443/hello-https -=== TEST 33: http to https get redirect +=== TEST 32: http to https get redirect --- request GET /hello-https --- more_headers @@ -839,7 +804,7 @@ Location: https://test.com:9443/hello-https -=== TEST 34: http to https head redirect +=== TEST 33: http to https head redirect --- request HEAD /hello-https --- more_headers @@ -852,7 +817,7 @@ Location: https://test.com:9443/hello-https -=== TEST 35: add plugin with new regex_uri: /test/1 redirect to http://test.com/1 +=== TEST 34: add plugin with new regex_uri: /test/1 redirect to http://test.com/1 --- config location /t { content_by_lua_block { @@ -891,7 +856,7 @@ passed -=== TEST 36: regex_uri redirect +=== TEST 35: regex_uri redirect --- request GET /test/1 --- response_headers @@ -902,7 +867,7 @@ Location: http://test.com/1 -=== TEST 37: regex_uri not match, get response from upstream +=== TEST 36: regex_uri not match, get response from upstream --- request GET /hello --- error_code: 200 @@ -913,7 +878,7 @@ hello world -=== TEST 38: add plugin with new regex_uri: encode_uri = true +=== TEST 37: add plugin with new regex_uri: encode_uri = true --- config location /t { content_by_lua_block { @@ -953,7 +918,7 @@ passed -=== TEST 39: regex_uri redirect with special characters +=== TEST 38: regex_uri redirect with special characters --- request GET /test/with%20space --- error_code: 200 @@ -965,7 +930,7 @@ Location: http://test.com/with%20space -=== TEST 40: add plugin with new uri: encode_uri = true +=== TEST 39: add plugin with new uri: encode_uri = true --- config location /t { content_by_lua_block { @@ -999,7 +964,7 @@ passed -=== TEST 41: redirect with special characters +=== TEST 40: redirect with special characters --- request GET /hello/with%20space --- response_headers @@ -1010,7 +975,7 @@ Location: /hello/with%20space -=== TEST 42: add plugin with new uri: $uri (append_query_string = true) +=== TEST 41: add plugin with new uri: $uri (append_query_string = true) --- config location /t { content_by_lua_block { @@ -1044,7 +1009,7 @@ passed -=== TEST 43: redirect +=== TEST 42: redirect --- request GET /hello?name=json --- response_headers @@ -1055,7 +1020,7 @@ Location: /hello?name=json -=== TEST 44: add plugin with new uri: $uri?type=string (append_query_string = true) +=== TEST 43: add plugin with new uri: $uri?type=string (append_query_string = true) --- config location /t { content_by_lua_block { @@ -1089,7 +1054,7 @@ passed -=== TEST 45: redirect +=== TEST 44: redirect --- request GET /hello?name=json --- response_headers @@ -1100,7 +1065,7 @@ Location: /hello?type=string&name=json -=== TEST 46: enable http_to_https (pass X-Forwarded-Proto) +=== TEST 45: enable http_to_https (pass X-Forwarded-Proto) --- config location /t { content_by_lua_block { @@ -1140,7 +1105,7 @@ passed -=== TEST 47: enable http_to_https (pass X-Forwarded-Proto) +=== TEST 46: enable http_to_https (pass X-Forwarded-Proto) --- request GET /hello --- more_headers @@ -1149,3 +1114,38 @@ X-Forwarded-Proto: http --- error_code: 301 --- response_headers Location: https://foo.com:9443/hello + + + +=== TEST 47: wrong configure, enable http_to_https with append_query_string +--- 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": true + } + } + }]] + ) + + if code >= 300 then + ngx.status = code + end + ngx.say(body) + } + } +--- request +GET /t +--- error_code: 400 +--- response_body eval +qr/error_msg":"failed to check the configuration of plugin redirect err: allOf 2 failed: value should match only one schema, but matches both schemas 1 and 2/ +--- no_error_log +[error] From 526b752b97f5b51449add85be24f7d94b4636ef1 Mon Sep 17 00:00:00 2001 From: vyvyan2010 <375636559@qq.com> Date: Wed, 13 Jul 2022 06:55:52 -0700 Subject: [PATCH 3/3] tweak: minor changes --- apisix/plugins/redirect.lua | 31 +++++++------------------------ t/plugin/redirect.t | 4 ++-- 2 files changed, 9 insertions(+), 26 deletions(-) diff --git a/apisix/plugins/redirect.lua b/apisix/plugins/redirect.lua index 23226f9030f5..fb2f75e683fc 100644 --- a/apisix/plugins/redirect.lua +++ b/apisix/plugins/redirect.lua @@ -57,30 +57,13 @@ local schema = { encode_uri = {type = "boolean", default = false}, append_query_string = {type = "boolean"}, }, - allOf = { - { - oneOf = { - {required = {"uri"}}, - {required = {"regex_uri"}}, - {required = {"http_to_https"}}, - }, - }, - -- append_query_string and http_to_https are exclusive - { - oneOf = { - {required = {"append_query_string"}}, - {required = {"http_to_https"}}, - { - ["not"] = { - anyOf = { - {required = {"append_query_string"}}, - {required = {"http_to_https"}}, - }, - }, - }, - }, - }, - }, + oneOf = { + {required = {"uri"}}, + {required = {"regex_uri"}}, + {required = {"http_to_https"}, ["not"] = { + required = {"append_query_string"} + }} + } } diff --git a/t/plugin/redirect.t b/t/plugin/redirect.t index 25b08078eff3..246c73ce7cad 100644 --- a/t/plugin/redirect.t +++ b/t/plugin/redirect.t @@ -582,7 +582,7 @@ 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: allOf 1 failed: value should match only one schema, but matches both schemas 1 and 3/ +qr/error_msg":"failed to check the configuration of plugin redirect err: value should match only one schema, but matches both schemas 1 and 3/ --- no_error_log [error] @@ -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: allOf 2 failed: value should match only one schema, but matches both schemas 1 and 2/ +qr/error_msg":"failed to check the configuration of plugin redirect err: value should match only one schema, but matches none/ --- no_error_log [error]