This is an automated email from the ASF dual-hosted git repository.

spacewander 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 d698220  fix: ignore the case of configured host (#3377)
d698220 is described below

commit d698220341776791f6e34568e0a17d52ab517919
Author: 罗泽轩 <[email protected]>
AuthorDate: Thu Jan 21 20:18:50 2021 -0600

    fix: ignore the case of configured host (#3377)
    
    Fix #3357.
    Signed-off-by: spacewander <[email protected]>
---
 apisix/http/route.lua             |  2 +-
 apisix/router.lua                 |  9 +++++
 rockspec/apisix-master-0.rockspec |  2 +-
 t/node/route-host.t               | 71 +++++++++++++++++++++++++++++++++++++++
 t/router/radixtree-host-uri2.t    | 42 +++++++++++++++++++++++
 5 files changed, 124 insertions(+), 2 deletions(-)

diff --git a/apisix/http/route.lua b/apisix/http/route.lua
index bdf3c9e..c5a5358 100644
--- a/apisix/http/route.lua
+++ b/apisix/http/route.lua
@@ -57,7 +57,7 @@ function _M.create_radixtree_uri_router(routes, uri_routes, 
with_parameter)
             end
 
             core.log.info("insert uri route: ",
-                          core.json.delay_encode(route.value))
+                          core.json.delay_encode(route.value, true))
             core.table.insert(uri_routes, {
                 paths = route.value.uris or route.value.uri,
                 methods = route.value.methods,
diff --git a/apisix/router.lua b/apisix/router.lua
index 51f03bd..036fa77 100644
--- a/apisix/router.lua
+++ b/apisix/router.lua
@@ -18,6 +18,7 @@ local require = require
 local http_route = require("apisix.http.route")
 local core    = require("apisix.core")
 local plugin_checker = require("apisix.plugin").plugin_checker
+local str_lower = string.lower
 local error   = error
 local pairs   = pairs
 local ipairs  = ipairs
@@ -32,6 +33,14 @@ local function filter(route)
         return
     end
 
+    if route.value.host then
+        route.value.host = str_lower(route.value.host)
+    elseif route.value.hosts then
+        for i, v in ipairs(route.value.hosts) do
+            route.value.hosts[i] = str_lower(v)
+        end
+    end
+
     if not route.value.upstream then
         return
     end
diff --git a/rockspec/apisix-master-0.rockspec 
b/rockspec/apisix-master-0.rockspec
index 2ee5009..7093964 100644
--- a/rockspec/apisix-master-0.rockspec
+++ b/rockspec/apisix-master-0.rockspec
@@ -43,7 +43,7 @@ dependencies = {
     "lua-resty-cookie = 0.1.0",
     "lua-resty-session = 2.24",
     "opentracing-openresty = 0.1",
-    "lua-resty-radixtree = 2.6",
+    "lua-resty-radixtree = 2.6.1",
     "lua-protobuf = 0.3.1",
     "lua-resty-openidc = 1.7.2-1",
     "luafilesystem = 1.7.0-2",
diff --git a/t/node/route-host.t b/t/node/route-host.t
index 7a965db..798501e 100644
--- a/t/node/route-host.t
+++ b/t/node/route-host.t
@@ -105,3 +105,74 @@ Host: foo.com
 hello world
 --- no_error_log
 [error]
+
+
+
+=== TEST 6: hit routes, uppercase
+--- request
+GET /hello
+--- more_headers
+Host: FOO.com
+--- response_body
+hello world
+--- no_error_log
+[error]
+
+
+
+=== TEST 7: set route(host is uppercase)
+--- 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"
+                        },
+                        "host": "FOO.com",
+                        "uri": "/hello"
+                }]]
+                )
+
+            if code >= 300 then
+                ngx.status = code
+            end
+            ngx.say(body)
+        }
+    }
+--- request
+GET /t
+--- response_body
+passed
+--- no_error_log
+[error]
+
+
+
+=== TEST 8: hit routes
+--- request
+GET /hello
+--- more_headers
+Host: foo.com
+--- response_body
+hello world
+--- no_error_log
+[error]
+
+
+
+=== TEST 9: hit routes, uppercase
+--- request
+GET /hello
+--- more_headers
+Host: FOO.com
+--- response_body
+hello world
+--- no_error_log
+[error]
diff --git a/t/router/radixtree-host-uri2.t b/t/router/radixtree-host-uri2.t
index df8a88d..20f034b 100644
--- a/t/router/radixtree-host-uri2.t
+++ b/t/router/radixtree-host-uri2.t
@@ -334,3 +334,45 @@ Host: t.com
 --- error_code: 404
 --- no_error_log
 [error]
+
+
+
+=== TEST 12: request host with uppercase
+--- yaml_config eval: $::yaml_config
+--- apisix_yaml
+routes:
+  -
+    uri: /server_port
+    host: test.com
+    upstream:
+        nodes:
+            "127.0.0.1:1981": 1
+        type: roundrobin
+#END
+--- request
+GET /server_port
+--- more_headers
+Host: tEst.com
+--- no_error_log
+[error]
+
+
+
+=== TEST 13: configure host with uppercase
+--- yaml_config eval: $::yaml_config
+--- apisix_yaml
+routes:
+  -
+    uri: /server_port
+    host: test.coM
+    upstream:
+        nodes:
+            "127.0.0.1:1981": 1
+        type: roundrobin
+#END
+--- request
+GET /server_port
+--- more_headers
+Host: test.com
+--- no_error_log
+[error]

Reply via email to