You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by me...@apache.org on 2022/04/06 08:53:23 UTC
[apisix] branch master updated: fix: allow `purge` method in `route` (#6780)
This is an automated email from the ASF dual-hosted git repository.
membphis 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 f56923521 fix: allow `purge` method in `route` (#6780)
f56923521 is described below
commit f56923521c4485c16dc4f13f6ed0cf215d4c5076
Author: soulbird <zh...@outlook.com>
AuthorDate: Wed Apr 6 16:53:16 2022 +0800
fix: allow `purge` method in `route` (#6780)
Co-authored-by: soulbird <zh...@gmail.com>
---
apisix/schema_def.lua | 2 +-
docs/en/latest/plugins/batch-requests.md | 2 +-
docs/en/latest/plugins/consumer-restriction.md | 2 +-
docs/zh/latest/admin-api.md | 2 +-
docs/zh/latest/plugins/batch-requests.md | 2 +-
docs/zh/latest/plugins/consumer-restriction.md | 2 +-
rockspec/apisix-master-0.rockspec | 2 +-
t/admin/routes3.t | 2 +-
t/fuzzing/serverless_route_test.py | 2 +-
t/fuzzing/simpleroute_test.py | 2 +-
t/fuzzing/vars_route_test.py | 2 +-
t/router/radixtree-method.t | 106 +++++++++++++++++++++++++
12 files changed, 117 insertions(+), 11 deletions(-)
diff --git a/apisix/schema_def.lua b/apisix/schema_def.lua
index b84ce3547..199bee1da 100644
--- a/apisix/schema_def.lua
+++ b/apisix/schema_def.lua
@@ -523,7 +523,7 @@ local method_schema = {
description = "HTTP method",
type = "string",
enum = {"GET", "POST", "PUT", "DELETE", "PATCH", "HEAD",
- "OPTIONS", "CONNECT", "TRACE"},
+ "OPTIONS", "CONNECT", "TRACE", "PURGE"},
}
_M.method_schema = method_schema
diff --git a/docs/en/latest/plugins/batch-requests.md b/docs/en/latest/plugins/batch-requests.md
index 7c5a5502e..67f7eeca2 100644
--- a/docs/en/latest/plugins/batch-requests.md
+++ b/docs/en/latest/plugins/batch-requests.md
@@ -85,7 +85,7 @@ The plugin will create a API in `apisix` to handle your batch request.
| Name | Type | Requirement | Default | Valid | Description |
| ---------- | ------- | ----------- | ------- | -------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- |
| version | string | optional | 1.1 | [1.0, 1.1] | http version |
-| method | string | optional | GET | ["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS", "CONNECT", "TRACE"] | http method |
+| method | string | optional | GET | ["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS", "CONNECT", "TRACE", "PURGE"] | http method |
| query | object | optional | | | request's `query string`, if `Key` is conflicted with global `query`, this setting's value will be used. |
| headers | object | optional | | | request's `header`, if `Key` is conflicted with global `headers`, this setting's value will be used. |
| path | string | required | | | http request's path |
diff --git a/docs/en/latest/plugins/consumer-restriction.md b/docs/en/latest/plugins/consumer-restriction.md
index 018c32172..a8ca55c9e 100644
--- a/docs/en/latest/plugins/consumer-restriction.md
+++ b/docs/en/latest/plugins/consumer-restriction.md
@@ -34,7 +34,7 @@ The `consumer-restriction` makes corresponding access restrictions based on diff
| blacklist | array[string] | required | | | Reject connection to all users specified in the provided list , **has the priority over `whitelist`** |
| rejected_code | integer | optional | 403 | [200,...] | The HTTP status code returned when the request is rejected. |
| rejected_msg | string | optional | | | The message returned when the request is rejected. |
-| allowed_by_methods | array[object] | optional | | | Set a list of allowed HTTP methods for the selected user , HTTP methods can be `["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS", "CONNECT", "TRACE"]` |
+| allowed_by_methods | array[object] | optional | | | Set a list of allowed HTTP methods for the selected user , HTTP methods can be `["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS", "CONNECT", "TRACE", "PURGE"]` |
For the `type` field is an enumerated type, it can be `consumer_name` or `service_id`. They stand for the following meanings:
diff --git a/docs/zh/latest/admin-api.md b/docs/zh/latest/admin-api.md
index 2880399c0..fc3829061 100644
--- a/docs/zh/latest/admin-api.md
+++ b/docs/zh/latest/admin-api.md
@@ -73,7 +73,7 @@ Admin API 是为 Apache APISIX 服务的一组 API,我们可以将参数传递
| hosts | 可选,不能与 `host` 一起使用 | 匹配规则 | 非空列表形态的 `host`,表示允许有多个不同 `host`,匹配其中任意一个即可。 | ["foo.com", "\*.bar.com"] |
| remote_addr | 可选,不能与 `remote_addrs` 一起使用 | 匹配规则 | 客户端请求 IP 地址:`192.168.1.101`、`192.168.1.102` 以及 CIDR 格式的支持 `192.168.1.0/24`。特别的,APISIX 也完整支持 IPv6 地址匹配:`::1`,`fe80::1`,`fe80::1/64` 等。 | "192.168.1.0/24" |
| remote_addrs | 可选,不能与 `remote_addr` 一起使用 | 匹配规则 | 非空列表形态的 `remote_addr`,表示允许有多个不同 IP 地址,符合其中任意一个即可。 | ["127.0.0.1", "192.0.0.0/8", "::1"] |
-| methods | 可选 | 匹配规则 | 如果为空或没有该选项,代表没有任何 `method` 限制,也可以是一个或多个的组合:`GET`,`POST`,`PUT`,`DELETE`,`PATCH`,`HEAD`,`OPTIONS`,`CONNECT`,`TRACE`。 | ["GET", "POST"] |
+| methods | 可选 | 匹配规则 | 如果为空或没有该选项,代表没有任何 `method` 限制,也可以是一个或多个的组合:`GET`,`POST`,`PUT`,`DELETE`,`PATCH`,`HEAD`,`OPTIONS`,`CONNECT`,`TRACE`,`PURGE`。 | ["GET", "POST"] |
| priority | 可选 | 匹配规则 | 如果不同路由包含相同 `uri`,根据属性 `priority` 确定哪个 `route` 被优先匹配,值越大优先级越高,默认值为 0。 | priority = 10 |
| vars | 可选 | 匹配规则 | 由一个或多个`[var, operator, val]`元素组成的列表,类似这样:`[[var, operator, val], [var, operator, val], ...]]`。例如:`["arg_name", "==", "json"]`,表示当前请求参数 `name` 是 `json`。这里的 `var` 与 Nginx 内部自身变量命名是保持一致,所以也可以使用 `request_uri`、`host` 等。更多细节请参考[lua-resty-expr](https://github.com/api7/lua-resty-expr) | [["arg_name", "==", "json"], ["arg_age", ">", 18]] |
| filter_func | 可选 | 匹配规则 | 用户自定义的过滤函数。可以使用它来实现特殊场景的匹配要求实现。该函数默认接受一个名为 vars 的输入参数,可以用它来获取 Nginx 变量。 | function(vars) return vars["arg_name"] == "json" end |
diff --git a/docs/zh/latest/plugins/batch-requests.md b/docs/zh/latest/plugins/batch-requests.md
index 9218d4cee..362cb3278 100644
--- a/docs/zh/latest/plugins/batch-requests.md
+++ b/docs/zh/latest/plugins/batch-requests.md
@@ -83,7 +83,7 @@ curl http://127.0.0.1:9080/apisix/admin/plugin_metadata/batch-requests -H 'X-API
| 参数名 | 类型 | 可选 | 默认值 | 有效值 | 描述 |
| ---------- | ------- | ---- | ------ | -------------------------------------------------------------------------------- | ------------------------------------------------------------------------- |
| version | string | 可选 | 1.1 | [1.0, 1.1] | 请求用的 `http` 协议版本 |
-| method | string | 可选 | GET | ["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS", "CONNECT", "TRACE"] | 请求使用的 `http` 方法 |
+| method | string | 可选 | GET | ["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS", "CONNECT", "TRACE", "PURGE"] | 请求使用的 `http` 方法 |
| query | object | 可选 | | | 独立请求所携带的 `query string`, 如果 `Key` 和全局的有冲突,以此设置为主。 |
| headers | object | 可选 | | | 独立请求所携带的 `header`, 如果 `Key` 和全局的有冲突,以此设置为主。 |
| path | string | 必须 | | | 请求路径 |
diff --git a/docs/zh/latest/plugins/consumer-restriction.md b/docs/zh/latest/plugins/consumer-restriction.md
index fbf37ab9a..f2211bc32 100644
--- a/docs/zh/latest/plugins/consumer-restriction.md
+++ b/docs/zh/latest/plugins/consumer-restriction.md
@@ -34,7 +34,7 @@ title: consumer-restriction
| blacklist | array[string] | 必选 | | | 与`whitelist`二选一,只能单独启用白名单或黑名单,两个不能一起使用。 |
| rejected_code | integer | 可选 | 403 | [200,...] | 当请求被拒绝时,返回的 HTTP 状态码。 |
| rejected_msg | String | 可选 | | | 当请求被拒绝时,返回的消息内容。 |
-| allowed_by_methods | array[object] | 可选 | | | 为用户设置允许的 HTTP methods 列表 , HTTP methods 可以为 `["GET","POST","PUT","DELETE","PATCH","HEAD","OPTIONS","CONNECT","TRACE"]` |
+| allowed_by_methods | array[object] | 可选 | | | 为用户设置允许的 HTTP methods 列表 , HTTP methods 可以为 `["GET","POST","PUT","DELETE","PATCH","HEAD","OPTIONS","CONNECT","TRACE", "PURGE"]` |
对于 `type` 字段是个枚举类型,它可以是 `consumer_name` 或 `service_id` 。分别代表以下含义:
diff --git a/rockspec/apisix-master-0.rockspec b/rockspec/apisix-master-0.rockspec
index d1ce6652a..aeb161e7b 100644
--- a/rockspec/apisix-master-0.rockspec
+++ b/rockspec/apisix-master-0.rockspec
@@ -45,7 +45,7 @@ dependencies = {
"lua-resty-cookie = 0.1.0",
"lua-resty-session = 3.10",
"opentracing-openresty = 0.1",
- "lua-resty-radixtree = 2.8.1",
+ "lua-resty-radixtree = 2.8.2",
"lua-protobuf = 0.3.4",
"lua-resty-openidc = 1.7.2-1",
"luafilesystem = 1.7.0-2",
diff --git a/t/admin/routes3.t b/t/admin/routes3.t
index 668ff47a7..60e4d4134 100644
--- a/t/admin/routes3.t
+++ b/t/admin/routes3.t
@@ -196,7 +196,7 @@ passed
ngx.HTTP_PUT,
[[{
"methods": ["GET", "POST", "PUT", "DELETE", "PATCH",
- "HEAD", "OPTIONS", "CONNECT", "TRACE"],
+ "HEAD", "OPTIONS", "CONNECT", "TRACE", "PURGE"],
"upstream": {
"nodes": {
"127.0.0.1:8080": 1
diff --git a/t/fuzzing/serverless_route_test.py b/t/fuzzing/serverless_route_test.py
index a1da0f31a..e84085f57 100644
--- a/t/fuzzing/serverless_route_test.py
+++ b/t/fuzzing/serverless_route_test.py
@@ -46,7 +46,7 @@ def run():
s_initialize(name="Request")
with s_block("Request-Line"):
- s_group("Method", ["GET", "HEAD", "POST", "PUT", "DELETE", "CONNECT", "OPTIONS", "TRACE"])
+ s_group("Method", ["GET", "HEAD", "POST", "PUT", "DELETE", "CONNECT", "OPTIONS", "TRACE", "PURGE"])
s_delim(" ", name="space-1")
s_string("/post", name="Request-URI")
s_delim(" ", name="space-2")
diff --git a/t/fuzzing/simpleroute_test.py b/t/fuzzing/simpleroute_test.py
index e48d01447..8a7e43119 100755
--- a/t/fuzzing/simpleroute_test.py
+++ b/t/fuzzing/simpleroute_test.py
@@ -41,7 +41,7 @@ def run():
s_initialize(name="Request")
with s_block("Request-Line"):
- s_group("Method", ['GET', 'HEAD', 'POST', 'PUT', 'DELETE', 'CONNECT', 'OPTIONS', 'TRACE'])
+ s_group("Method", ['GET', 'HEAD', 'POST', 'PUT', 'DELETE', 'CONNECT', 'OPTIONS', 'TRACE', "PURGE"])
s_delim(" ", name='space-1')
s_string("/get", name='Request-URI')
s_delim(" ", name='space-2')
diff --git a/t/fuzzing/vars_route_test.py b/t/fuzzing/vars_route_test.py
index da89a0905..c2559fe3d 100644
--- a/t/fuzzing/vars_route_test.py
+++ b/t/fuzzing/vars_route_test.py
@@ -44,7 +44,7 @@ def run():
s_initialize(name="Request")
with s_block("Request-Line"):
- s_group("Method", ['GET', 'HEAD', 'POST', 'PUT', 'DELETE', 'CONNECT', 'OPTIONS', 'TRACE'])
+ s_group("Method", ['GET', 'HEAD', 'POST', 'PUT', 'DELETE', 'CONNECT', 'OPTIONS', 'TRACE', 'PURGE'])
s_delim(" ", name='space-1')
s_string("/parameter?name=jack", name='Request-URI')
s_delim(" ", name='space-2')
diff --git a/t/router/radixtree-method.t b/t/router/radixtree-method.t
new file mode 100644
index 000000000..8f14c3aa6
--- /dev/null
+++ b/t/router/radixtree-method.t
@@ -0,0 +1,106 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+use t::APISIX 'no_plan';
+
+add_block_preprocessor(sub {
+ my ($block) = @_;
+
+ if ((!defined $block->error_log) && (!defined $block->no_error_log)) {
+ $block->set_value("no_error_log", "[error]");
+ }
+
+ if (!defined $block->request) {
+ $block->set_value("request", "GET /t");
+ }
+
+});
+
+run_tests;
+
+__DATA__
+
+=== TEST 1: set route without PURGE method
+--- 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,
+ [[{
+ "methods": ["GET"],
+ "upstream": {
+ "nodes": {
+ "127.0.0.1:1980": 1
+ },
+ "type": "roundrobin"
+ },
+ "uri": "/hello"
+ }]]
+ )
+
+ if code >= 300 then
+ ngx.status = code
+ end
+ ngx.say(body)
+ }
+ }
+--- response_body
+passed
+
+
+
+=== TEST 2: route mismatch
+--- request
+PURGE /hello
+--- error_code: 404
+
+
+
+=== TEST 3: set route with PURGE method
+--- 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,
+ [[{
+ "methods": ["GET", "PURGE"],
+ "upstream": {
+ "nodes": {
+ "127.0.0.1:1980": 1
+ },
+ "type": "roundrobin"
+ },
+ "uri": "/hello"
+ }]]
+ )
+
+ if code >= 300 then
+ ngx.status = code
+ end
+ ngx.say(body)
+ }
+ }
+--- response_body
+passed
+
+
+
+=== TEST 4: route match PURGE method
+--- request
+PURGE /hello
+--- error_code: 200