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 2020/01/03 02:11:45 UTC
[incubator-apisix] branch master updated: change: responsed a
better tip when failed to match any route. (#1013)
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/incubator-apisix.git
The following commit(s) were added to refs/heads/master by this push:
new 9e98773 change: responsed a better tip when failed to match any route. (#1013)
9e98773 is described below
commit 9e98773fae6b19e4908090f8ab34eab2b4e39c04
Author: YuanSheng Wang <me...@gmail.com>
AuthorDate: Fri Jan 3 10:11:37 2020 +0800
change: responsed a better tip when failed to match any route. (#1013)
---
lua/apisix.lua | 2 +-
lua/apisix/http/router/radixtree_host_uri.lua | 2 +-
lua/apisix/http/router/radixtree_uri.lua | 4 ++--
t/debug/hook.t | 4 ++--
t/node/global-rule.t | 8 +++----
t/node/hosts.t | 8 +++----
t/node/invalid-route.t | 4 ++--
t/node/invalid-service.t | 4 ++--
t/node/invalid-upstream.t | 4 ++--
t/node/merge-route.t | 4 ++--
t/node/not-exist-service.t | 2 +-
t/node/not-exist-upstream.t | 4 ++--
t/node/remote-addr-ipv6.t | 12 +++++-----
t/node/remote-addr.t | 8 +++----
t/node/remote_addrs.t | 6 ++---
t/node/route-domain.t | 4 ++--
t/node/route-filter-func.t | 4 ++--
t/node/route-host.t | 12 +++++-----
t/node/route-uris.t | 2 --
t/node/sanity-radixtree.t | 8 +++----
t/node/upstream-domain.t | 4 ++--
t/node/upstream-ipv6.t | 4 ++--
t/node/upstream.t | 4 ++--
t/node/vars.t | 32 +++++++++++++--------------
t/node/wildcard-host.t | 8 +++----
t/router/radixtree-host-uri.t | 20 ++++++++---------
t/router/radixtree-uri-host.t | 20 +++++------------
t/router/radixtree-uri-multiple.t | 4 ++--
t/router/radixtree-uri-sanity.t | 20 ++++++++---------
29 files changed, 105 insertions(+), 117 deletions(-)
diff --git a/lua/apisix.lua b/lua/apisix.lua
index 741862c..63319cd 100644
--- a/lua/apisix.lua
+++ b/lua/apisix.lua
@@ -268,7 +268,7 @@ function _M.http_access_phase()
local route = api_ctx.matched_route
if not route then
- return core.response.exit(404)
+ return core.response.exit(404, {error_msg = "failed to match any routes"})
end
if route.value.service_protocol == "grpc" then
diff --git a/lua/apisix/http/router/radixtree_host_uri.lua b/lua/apisix/http/router/radixtree_host_uri.lua
index 960b8a0..cee7b2c 100644
--- a/lua/apisix/http/router/radixtree_host_uri.lua
+++ b/lua/apisix/http/router/radixtree_host_uri.lua
@@ -158,7 +158,7 @@ function _M.match(api_ctx)
end
core.log.info("not find any matched route")
- return core.response.exit(404)
+ return true
end
diff --git a/lua/apisix/http/router/radixtree_uri.lua b/lua/apisix/http/router/radixtree_uri.lua
index c84062e..dfcd654 100644
--- a/lua/apisix/http/router/radixtree_uri.lua
+++ b/lua/apisix/http/router/radixtree_uri.lua
@@ -98,7 +98,7 @@ function _M.match(api_ctx)
if not uri_router then
core.log.error("failed to fetch valid `uri` router: ")
- return core.response.exit(404)
+ return true
end
core.table.clear(match_opts)
@@ -110,7 +110,7 @@ function _M.match(api_ctx)
local ok = uri_router:dispatch(api_ctx.var.uri, match_opts, api_ctx)
if not ok then
core.log.info("not find any matched route")
- return core.response.exit(404)
+ return true
end
return true
diff --git a/t/debug/hook.t b/t/debug/hook.t
index 2d76d24..49bce20 100644
--- a/t/debug/hook.t
+++ b/t/debug/hook.t
@@ -84,8 +84,8 @@ passed
--- request
GET /not_found
--- error_code: 404
---- response_body eval
-qr/404 Not Found/
+--- response_body
+{"error_msg":"failed to match any routes"}
--- no_error_log
[error]
diff --git a/t/node/global-rule.t b/t/node/global-rule.t
index 6eb64f0..c1de5dd 100644
--- a/t/node/global-rule.t
+++ b/t/node/global-rule.t
@@ -93,8 +93,8 @@ passed
--- request
GET /not_found
--- error_code: 404
---- response_body eval
-qr/404 Not Found/
+--- response_body
+{"error_msg":"failed to match any routes"}
--- no_error_log
[error]
@@ -104,8 +104,8 @@ qr/404 Not Found/
--- request
GET /hello
--- error_code: 404
---- response_body eval
-qr/404 Not Found/
+--- response_body
+{"error_msg":"failed to match any routes"}
--- no_error_log
[error]
diff --git a/t/node/hosts.t b/t/node/hosts.t
index 2425d6b..0dc8dc3 100644
--- a/t/node/hosts.t
+++ b/t/node/hosts.t
@@ -64,8 +64,8 @@ passed
--- request
GET /not_found
--- error_code: 404
---- response_body eval
-qr/404 Not Found/
+--- response_body
+{"error_msg":"failed to match any routes"}
--- no_error_log
[error]
@@ -77,8 +77,8 @@ GET /hello
--- more_headers
Host: not_found.com
--- error_code: 404
---- response_body eval
-qr/404 Not Found/
+--- response_body
+{"error_msg":"failed to match any routes"}
--- no_error_log
[error]
diff --git a/t/node/invalid-route.t b/t/node/invalid-route.t
index 0adf1a2..4b37927 100644
--- a/t/node/invalid-route.t
+++ b/t/node/invalid-route.t
@@ -56,8 +56,8 @@ qr/"value":"mexxxxxxxxxxxxxxx"/
--- request
GET /not_found
--- error_code: 404
---- response_body_like eval
-qr/404 Not Found/
+--- response_body
+{"error_msg":"failed to match any routes"}
--- grep_error_log eval
qr/\[error\].*/
--- grep_error_log_out eval
diff --git a/t/node/invalid-service.t b/t/node/invalid-service.t
index 41b4b0d..4a6af13 100644
--- a/t/node/invalid-service.t
+++ b/t/node/invalid-service.t
@@ -57,8 +57,8 @@ qr/"value":"mexxxxxxxxxxxxxxx"/
--- request
GET /not_found
--- error_code: 404
---- response_body_like eval
-qr/404 Not Found/
+--- response_body
+{"error_msg":"failed to match any routes"}
--- grep_error_log eval
qr/\[error\].*/
--- grep_error_log_out eval
diff --git a/t/node/invalid-upstream.t b/t/node/invalid-upstream.t
index aff6c34..b6138ab 100644
--- a/t/node/invalid-upstream.t
+++ b/t/node/invalid-upstream.t
@@ -56,8 +56,8 @@ qr/"value":"mexxxxxxxxxxxxxxx"/
--- request
GET /not_found
--- error_code: 404
---- response_body_like eval
-qr/404 Not Found/
+--- response_body
+{"error_msg":"failed to match any routes"}
--- grep_error_log eval
qr/\[error\].*/
--- grep_error_log_out eval
diff --git a/t/node/merge-route.t b/t/node/merge-route.t
index d4eb59d..ae52c05 100644
--- a/t/node/merge-route.t
+++ b/t/node/merge-route.t
@@ -102,8 +102,8 @@ passed
--- request
GET /not_found
--- error_code: 404
---- response_body eval
-qr/404 Not Found/
+--- response_body
+{"error_msg":"failed to match any routes"}
--- no_error_log
[error]
diff --git a/t/node/not-exist-service.t b/t/node/not-exist-service.t
index f068871..aa313ed 100644
--- a/t/node/not-exist-service.t
+++ b/t/node/not-exist-service.t
@@ -57,7 +57,7 @@ passed
--- request
GET /hello
--- error_code: 404
---- response_body_like eval
+--- response_body eval
qr/404 Not Found/
--- wait_etcd_sync: 0.3
--- grep_error_log eval
diff --git a/t/node/not-exist-upstream.t b/t/node/not-exist-upstream.t
index c12aa10..a5a008d 100644
--- a/t/node/not-exist-upstream.t
+++ b/t/node/not-exist-upstream.t
@@ -67,8 +67,8 @@ passed
--- request
GET /not_found
--- error_code: 404
---- response_body_like eval
-qr/404 Not Found/
+--- response_body
+{"error_msg":"failed to match any routes"}
--- no_error_log
[error]
diff --git a/t/node/remote-addr-ipv6.t b/t/node/remote-addr-ipv6.t
index 3eeb531..fdc469d 100644
--- a/t/node/remote-addr-ipv6.t
+++ b/t/node/remote-addr-ipv6.t
@@ -77,8 +77,8 @@ location /t {
}
--- request
GET /t
---- response_body_like eval
-qr{.*404 Not Found.*}
+--- response_body eval
+qr/"error_msg":"failed to match any routes"/
--- no_error_log
[error]
@@ -89,8 +89,8 @@ qr{.*404 Not Found.*}
--- request
GET /not_found
--- error_code: 404
---- response_body_like eval
-qr{.*404 Not Found.*}
+--- response_body eval
+qr/"error_msg":"failed to match any routes"/
--- no_error_log
[error]
@@ -129,7 +129,7 @@ close: 1 nil
--- request
GET /hello
--- error_code: 404
---- response_body_like eval
-qr{.*404 Not Found.*}
+--- response_body
+{"error_msg":"failed to match any routes"}
--- no_error_log
[error]
diff --git a/t/node/remote-addr.t b/t/node/remote-addr.t
index 8f2e569..9d51980 100644
--- a/t/node/remote-addr.t
+++ b/t/node/remote-addr.t
@@ -61,8 +61,8 @@ passed
--- request
GET /not_found
--- error_code: 404
---- response_body eval
-qr/404 Not Found/
+--- response_body
+{"error_msg":"failed to match any routes"}
--- no_error_log
[error]
@@ -117,8 +117,8 @@ passed
--- request
GET /hello
--- error_code: 404
---- response_body_like eval
-qr/404 Not Found/
+--- response_body
+{"error_msg":"failed to match any routes"}
--- no_error_log
[error]
diff --git a/t/node/remote_addrs.t b/t/node/remote_addrs.t
index 8da470e..5abbea1 100644
--- a/t/node/remote_addrs.t
+++ b/t/node/remote_addrs.t
@@ -68,8 +68,8 @@ set_real_ip_from unix:;
--- request
GET /not_found
--- error_code: 404
---- response_body eval
-qr/404 Not Found/
+--- response_body
+{"error_msg":"failed to match any routes"}
--- no_error_log
[error]
@@ -85,8 +85,6 @@ GET /hello
--- more_headers
Host: not_found.com
--- error_code: 404
---- response_body eval
-qr/404 Not Found/
--- no_error_log
[error]
diff --git a/t/node/route-domain.t b/t/node/route-domain.t
index 06e10d7..05bc3d9 100644
--- a/t/node/route-domain.t
+++ b/t/node/route-domain.t
@@ -64,8 +64,8 @@ passed
--- request
GET /not_found
--- error_code: 404
---- response_body eval
-qr/404 Not Found/
+--- response_body
+{"error_msg":"failed to match any routes"}
--- no_error_log
[error]
diff --git a/t/node/route-filter-func.t b/t/node/route-filter-func.t
index fc9671c..6c67f41 100644
--- a/t/node/route-filter-func.t
+++ b/t/node/route-filter-func.t
@@ -64,8 +64,8 @@ passed
--- request
GET /hello?name=unknown
--- error_code: 404
---- response_body eval
-qr/404 Not Found/
+--- response_body
+{"error_msg":"failed to match any routes"}
--- no_error_log
[error]
diff --git a/t/node/route-host.t b/t/node/route-host.t
index 2ccc6a6..04a5a0d 100644
--- a/t/node/route-host.t
+++ b/t/node/route-host.t
@@ -65,8 +65,8 @@ passed
--- request
GET /not_found
--- error_code: 404
---- response_body eval
-qr/404 Not Found/
+--- response_body
+{"error_msg":"failed to match any routes"}
--- no_error_log
[error]
@@ -76,8 +76,8 @@ qr/404 Not Found/
--- request
GET /hello
--- error_code: 404
---- response_body eval
-qr/404 Not Found/
+--- response_body
+{"error_msg":"failed to match any routes"}
--- no_error_log
[error]
@@ -89,8 +89,8 @@ GET /hello
--- more_headers
Host: not_found.com
--- error_code: 404
---- response_body eval
-qr/404 Not Found/
+--- response_body
+{"error_msg":"failed to match any routes"}
--- no_error_log
[error]
diff --git a/t/node/route-uris.t b/t/node/route-uris.t
index 08ea83c..d22d5ef 100644
--- a/t/node/route-uris.t
+++ b/t/node/route-uris.t
@@ -64,8 +64,6 @@ passed
--- request
GET /not_found
--- error_code: 404
---- response_body eval
-qr/404 Not Found/
--- no_error_log
[error]
diff --git a/t/node/sanity-radixtree.t b/t/node/sanity-radixtree.t
index 36e4b98..9f4a5c3 100644
--- a/t/node/sanity-radixtree.t
+++ b/t/node/sanity-radixtree.t
@@ -64,8 +64,8 @@ passed
--- request
GET /not_found
--- error_code: 404
---- response_body eval
-qr/404 Not Found/
+--- response_body
+{"error_msg":"failed to match any routes"}
--- no_error_log
[error]
@@ -149,7 +149,7 @@ qr/404 Not Found/
--- request
GET /hel
--- error_code: 404
---- response_body eval
-qr/404 Not Found/
+--- response_body
+{"error_msg":"failed to match any routes"}
--- no_error_log
[error]
diff --git a/t/node/upstream-domain.t b/t/node/upstream-domain.t
index ca03a63..426dc87 100644
--- a/t/node/upstream-domain.t
+++ b/t/node/upstream-domain.t
@@ -90,8 +90,8 @@ passed
--- request
GET /not_found
--- error_code: 404
---- response_body eval
-qr/404 Not Found/
+--- response_body
+{"error_msg":"failed to match any routes"}
--- no_error_log
[error]
diff --git a/t/node/upstream-ipv6.t b/t/node/upstream-ipv6.t
index 36f9478..23eaa56 100644
--- a/t/node/upstream-ipv6.t
+++ b/t/node/upstream-ipv6.t
@@ -102,8 +102,8 @@ passed
--- request
GET /not_found
--- error_code: 404
---- response_body eval
-qr/404 Not Found/
+--- response_body
+{"error_msg":"failed to match any routes"}
--- no_error_log
[error]
diff --git a/t/node/upstream.t b/t/node/upstream.t
index 598b3a0..bfdbba9 100644
--- a/t/node/upstream.t
+++ b/t/node/upstream.t
@@ -89,8 +89,8 @@ passed
--- request
GET /not_found
--- error_code: 404
---- response_body eval
-qr/404 Not Found/
+--- response_body
+{"error_msg":"failed to match any routes"}
--- no_error_log
[error]
diff --git a/t/node/vars.t b/t/node/vars.t
index a1552bf..fdbe22e 100644
--- a/t/node/vars.t
+++ b/t/node/vars.t
@@ -63,8 +63,8 @@ passed
--- request
GET /not_found
--- error_code: 404
---- response_body eval
-qr/404 Not Found/
+--- response_body
+{"error_msg":"failed to match any routes"}
--- no_error_log
[error]
@@ -74,8 +74,8 @@ qr/404 Not Found/
--- request
GET /hello?k=not-hit
--- error_code: 404
---- response_body eval
-qr/404 Not Found/
+--- response_body
+{"error_msg":"failed to match any routes"}
--- no_error_log
[error]
@@ -129,8 +129,8 @@ passed
--- request
GET /hello
--- error_code: 404
---- response_body eval
-qr/404 Not Found/
+--- response_body
+{"error_msg":"failed to match any routes"}
--- no_error_log
[error]
@@ -142,8 +142,8 @@ Cookie: k=not-hit; kkk=vvv;
--- request
GET /hello
--- error_code: 404
---- response_body eval
-qr/404 Not Found/
+--- response_body
+{"error_msg":"failed to match any routes"}
--- no_error_log
[error]
@@ -199,8 +199,8 @@ passed
--- request
GET /hello
--- error_code: 404
---- response_body eval
-qr/404 Not Found/
+--- response_body
+{"error_msg":"failed to match any routes"}
--- no_error_log
[error]
@@ -212,8 +212,8 @@ k: not-hit
--- request
GET /hello
--- error_code: 404
---- response_body eval
-qr/404 Not Found/
+--- response_body
+{"error_msg":"failed to match any routes"}
--- no_error_log
[error]
@@ -269,8 +269,8 @@ passed
--- request
GET /hello
--- error_code: 404
---- response_body eval
-qr/404 Not Found/
+--- response_body
+{"error_msg":"failed to match any routes"}
--- no_error_log
[error]
@@ -282,8 +282,8 @@ k: header
--- request
GET /hello
--- error_code: 404
---- response_body eval
-qr/404 Not Found/
+--- response_body
+{"error_msg":"failed to match any routes"}
--- no_error_log
[error]
diff --git a/t/node/wildcard-host.t b/t/node/wildcard-host.t
index 8def761..5bfb95e 100644
--- a/t/node/wildcard-host.t
+++ b/t/node/wildcard-host.t
@@ -61,8 +61,8 @@ passed
--- request
GET /not_found
--- error_code: 404
---- response_body eval
-qr/404 Not Found/
+--- response_body
+{"error_msg":"failed to match any routes"}
--- no_error_log
[error]
@@ -72,8 +72,8 @@ qr/404 Not Found/
--- request
GET /hello
--- error_code: 404
---- response_body eval
-qr/404 Not Found/
+--- response_body
+{"error_msg":"failed to match any routes"}
--- no_error_log
[error]
diff --git a/t/router/radixtree-host-uri.t b/t/router/radixtree-host-uri.t
index bfdd6ec..f80e3eb 100644
--- a/t/router/radixtree-host-uri.t
+++ b/t/router/radixtree-host-uri.t
@@ -80,8 +80,8 @@ passed
GET /not_found
--- yaml_config eval: $::yaml_config
--- error_code: 404
---- response_body eval
-qr/404 Not Found/
+--- response_body
+{"error_msg":"failed to match any routes"}
--- no_error_log
[error]
@@ -92,8 +92,8 @@ qr/404 Not Found/
GET /hello
--- yaml_config eval: $::yaml_config
--- error_code: 404
---- response_body eval
-qr/404 Not Found/
+--- response_body
+{"error_msg":"failed to match any routes"}
--- no_error_log
[error]
@@ -106,8 +106,8 @@ GET /hello
--- more_headers
Host: not_found.com
--- error_code: 404
---- response_body eval
-qr/404 Not Found/
+--- response_body
+{"error_msg":"failed to match any routes"}
--- no_error_log
[error]
@@ -176,8 +176,8 @@ passed
GET /hello
--- yaml_config eval: $::yaml_config
--- error_code: 404
---- response_body eval
-qr/404 Not Found/
+--- response_body
+{"error_msg":"failed to match any routes"}
--- no_error_log
[error]
@@ -235,8 +235,8 @@ passed
GET /hello2
--- yaml_config eval: $::yaml_config
--- error_code: 404
---- response_body eval
-qr/404 Not Found/
+--- response_body
+{"error_msg":"failed to match any routes"}
--- no_error_log
[error]
diff --git a/t/router/radixtree-uri-host.t b/t/router/radixtree-uri-host.t
index 625d27d..cefe0a0 100644
--- a/t/router/radixtree-uri-host.t
+++ b/t/router/radixtree-uri-host.t
@@ -80,8 +80,8 @@ passed
GET /not_found
--- yaml_config eval: $::yaml_config
--- error_code: 404
---- response_body eval
-qr/404 Not Found/
+--- response_body
+{"error_msg":"failed to match any routes"}
--- no_error_log
[error]
@@ -92,8 +92,6 @@ qr/404 Not Found/
GET /hello
--- yaml_config eval: $::yaml_config
--- error_code: 404
---- response_body eval
-qr/404 Not Found/
--- no_error_log
[error]
@@ -106,8 +104,6 @@ GET /hello
--- more_headers
Host: not_found.com
--- error_code: 404
---- response_body eval
-qr/404 Not Found/
--- no_error_log
[error]
@@ -180,8 +176,8 @@ passed
GET /not_found
--- yaml_config eval: $::yaml_config
--- error_code: 404
---- response_body eval
-qr/404 Not Found/
+--- response_body
+{"error_msg":"failed to match any routes"}
--- no_error_log
[error]
@@ -192,8 +188,6 @@ qr/404 Not Found/
GET /hello
--- yaml_config eval: $::yaml_config
--- error_code: 404
---- response_body eval
-qr/404 Not Found/
--- no_error_log
[error]
@@ -206,8 +200,6 @@ GET /hello
--- more_headers
Host: www.foo.com
--- error_code: 404
---- response_body eval
-qr/404 Not Found/
--- no_error_log
[error]
@@ -264,8 +256,8 @@ passed
--- request
GET /hello?name=unknown
--- error_code: 404
---- response_body eval
-qr/404 Not Found/
+--- response_body
+{"error_msg":"failed to match any routes"}
--- no_error_log
[error]
diff --git a/t/router/radixtree-uri-multiple.t b/t/router/radixtree-uri-multiple.t
index ebd94b4..f591fd7 100644
--- a/t/router/radixtree-uri-multiple.t
+++ b/t/router/radixtree-uri-multiple.t
@@ -146,8 +146,8 @@ passed
GET /not_found
--- yaml_config eval: $::yaml_config
--- error_code: 404
---- response_body eval
-qr/404 Not Found/
+--- response_body
+{"error_msg":"failed to match any routes"}
--- no_error_log
[error]
diff --git a/t/router/radixtree-uri-sanity.t b/t/router/radixtree-uri-sanity.t
index c037feb..d34ecbc 100644
--- a/t/router/radixtree-uri-sanity.t
+++ b/t/router/radixtree-uri-sanity.t
@@ -80,8 +80,8 @@ passed
GET /not_found
--- yaml_config eval: $::yaml_config
--- error_code: 404
---- response_body eval
-qr/404 Not Found/
+--- response_body
+{"error_msg":"failed to match any routes"}
--- no_error_log
[error]
@@ -92,8 +92,8 @@ qr/404 Not Found/
GET /hello
--- yaml_config eval: $::yaml_config
--- error_code: 404
---- response_body eval
-qr/404 Not Found/
+--- response_body
+{"error_msg":"failed to match any routes"}
--- no_error_log
[error]
@@ -106,8 +106,8 @@ GET /hello
--- more_headers
Host: not_found.com
--- error_code: 404
---- response_body eval
-qr/404 Not Found/
+--- response_body
+{"error_msg":"failed to match any routes"}
--- no_error_log
[error]
@@ -166,8 +166,8 @@ passed
GET /hello
--- yaml_config eval: $::yaml_config
--- error_code: 404
---- response_body eval
-qr/404 Not Found/
+--- response_body
+{"error_msg":"failed to match any routes"}
--- no_error_log
[error]
@@ -226,8 +226,8 @@ passed
GET /hello2
--- yaml_config eval: $::yaml_config
--- error_code: 404
---- response_body eval
-qr/404 Not Found/
+--- response_body
+{"error_msg":"failed to match any routes"}
--- no_error_log
[error]