You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by sh...@apache.org on 2019/11/04 06:01:00 UTC
[incubator-apisix] branch master updated: Fix: allow set multiple
URI in one route config (#797)
This is an automated email from the ASF dual-hosted git repository.
shuaijinchao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-apisix.git
The following commit(s) were added to refs/heads/master by this push:
new b91d2d3 Fix: allow set multiple URI in one route config (#797)
b91d2d3 is described below
commit b91d2d36c05501d6eeba97eecb84b30d792c0514
Author: Lien <li...@users.noreply.github.com>
AuthorDate: Mon Nov 4 14:00:52 2019 +0800
Fix: allow set multiple URI in one route config (#797)
* route support uris
* fix uris in router with test cases
* remove line has trailing whitespace
* remove line has trailing whitespace
* fix test case
* use new test case for multiple uris
---
lua/apisix/schema_def.lua | 11 ++++++
t/admin/routes.t | 31 ++++++++++++++++
t/node/route-uris.t | 90 +++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 132 insertions(+)
diff --git a/lua/apisix/schema_def.lua b/lua/apisix/schema_def.lua
index fc70770..859be9f 100644
--- a/lua/apisix/schema_def.lua
+++ b/lua/apisix/schema_def.lua
@@ -267,6 +267,14 @@ _M.route = {
type = "object",
properties = {
uri = {type = "string", minLength = 1, maxLength = 4096},
+ uris = {
+ type = "array",
+ items = {
+ description = "HTTP uri",
+ type = "string",
+ },
+ uniqueItems = true,
+ },
desc = {type = "string", maxLength = 256},
methods = {
@@ -327,6 +335,9 @@ _M.route = {
{required = {"upstream", "uri"}},
{required = {"upstream_id", "uri"}},
{required = {"service_id", "uri"}},
+ {required = {"upstream", "uris"}},
+ {required = {"upstream_id", "uris"}},
+ {required = {"service_id", "uris"}},
},
additionalProperties = false,
}
diff --git a/t/admin/routes.t b/t/admin/routes.t
index 78e26d8..1b8d8ac 100644
--- a/t/admin/routes.t
+++ b/t/admin/routes.t
@@ -1330,3 +1330,34 @@ GET /t
{"error_msg":"failed to load 'filter_func' string: [string \"return function(vars) \"]:1: 'end' expected near '<eof>'"}
--- no_error_log
[error]
+
+
+
+=== TEST 37: Support for multiple URIs
+--- 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,
+ [=[{
+ "uris": ["/index.html","/index2.html"],
+ "upstream": {
+ "nodes": {
+ "127.0.0.1:8080": 1
+ },
+ "type": "roundrobin"
+ }
+ }]=]
+ )
+
+ ngx.status = code
+ ngx.say(body)
+ }
+ }
+--- request
+GET /t
+--- response_body
+passed
+--- no_error_log
+[error]
diff --git a/t/node/route-uris.t b/t/node/route-uris.t
new file mode 100644
index 0000000..08ea83c
--- /dev/null
+++ b/t/node/route-uris.t
@@ -0,0 +1,90 @@
+#
+# 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';
+
+repeat_each(1);
+log_level('info');
+worker_connections(256);
+no_root_location();
+no_shuffle();
+
+run_tests();
+
+__DATA__
+
+=== TEST 1: set route(id: 1)
+--- 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"
+ },
+ "uris": ["/hello","/hello1"]
+ }]]
+ )
+
+ if code >= 300 then
+ ngx.status = code
+ end
+ ngx.say(body)
+ }
+ }
+--- request
+GET /t
+--- response_body
+passed
+--- no_error_log
+[error]
+
+
+
+=== TEST 2: /not_found
+--- request
+GET /not_found
+--- error_code: 404
+--- response_body eval
+qr/404 Not Found/
+--- no_error_log
+[error]
+
+
+
+=== TEST 3: hit routes1
+--- request
+GET /hello
+--- response_body
+hello world
+--- no_error_log
+[error]
+
+
+
+=== TEST 4: hit routes2
+--- request
+GET /hello1
+--- response_body
+hello1 world
+--- no_error_log
+[error]