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 076ecf3  bugfix: should not drop the error msg of `dns_parse`. (#1398)
076ecf3 is described below

commit 076ecf3ade61b73a5b4105217bebf624f030755f
Author: YuanSheng Wang <[email protected]>
AuthorDate: Mon Apr 6 11:04:09 2020 +0800

    bugfix: should not drop the error msg of `dns_parse`. (#1398)
    
    fix #573 .
---
 apisix/init.lua        |  9 +++++++--
 t/node/invalid-route.t | 43 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 50 insertions(+), 2 deletions(-)

diff --git a/apisix/init.lua b/apisix/init.lua
index 550afa1..aa8598e 100644
--- a/apisix/init.lua
+++ b/apisix/init.lua
@@ -347,8 +347,13 @@ function _M.http_access_phase()
 
     else
         if route.has_domain then
-            route = parsed_domain(route, api_ctx.conf_version,
-                                  parse_domain_in_route, route)
+            local err
+            route, err = parsed_domain(route, api_ctx.conf_version,
+                                       parse_domain_in_route, route)
+            if err then
+                core.log.error("failed to parse domain in route: ", err)
+                return core.response.exit(500)
+            end
         end
 
         if route.value.upstream and route.value.upstream.enable_websocket then
diff --git a/t/node/invalid-route.t b/t/node/invalid-route.t
index 4b37927..51d6c53 100644
--- a/t/node/invalid-route.t
+++ b/t/node/invalid-route.t
@@ -115,3 +115,46 @@ GET /t
 done
 --- no_error_log
 [error]
+
+
+
+=== TEST 5: set route(with invalid host)
+--- 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": "/server_port",
+                    "upstream": {
+                        "key": "remote_addr",
+                        "type": "chash",
+                        "nodes": {
+                            "xxxx.invalid:1980": 1
+                        }
+                    }
+                }]]
+                )
+
+            if code >= 300 then
+                ngx.status = code
+            end
+            ngx.say(body)
+        }
+    }
+--- request
+GET /t
+--- response_body
+passed
+--- no_error_log
+[error]
+
+
+
+=== TEST 6: hit route
+--- request
+GET /server_port
+--- error_code: 500
+--- error_log
+failed to parse domain in route: server returned error code: 3: name error

Reply via email to