This is an automated email from the ASF dual-hosted git repository.
AlinsRan 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 78800ae3a fix: normalize the case of hosts carried on a service
(#13781)
78800ae3a is described below
commit 78800ae3a68aacc82118ab72876ec667c68b434d
Author: AlinsRan <[email protected]>
AuthorDate: Fri Aug 7 13:30:38 2026 +0800
fix: normalize the case of hosts carried on a service (#13781)
---
apisix/http/service.lua | 9 ++++++
t/router/radixtree-host-uri3.t | 64 ++++++++++++++++++++++++++++++++++++++++++
2 files changed, 73 insertions(+)
diff --git a/apisix/http/service.lua b/apisix/http/service.lua
index 66bb21023..196d8ed2e 100644
--- a/apisix/http/service.lua
+++ b/apisix/http/service.lua
@@ -20,6 +20,8 @@ local plugin_checker = require("apisix.plugin").plugin_checker
local plugin = require("apisix.plugin")
local services
local error = error
+local ipairs = ipairs
+local str_lower = string.lower
local _M = {
@@ -47,6 +49,13 @@ local function filter(service)
return
end
+ -- normalize the hosts like `apisix/router.lua` does for routes: hostnames
are
+ -- case-insensitive, and they are matched against $host, which is always
lowercase
+ if service.value.hosts then
+ for i, v in ipairs(service.value.hosts) do
+ service.value.hosts[i] = str_lower(v)
+ end
+ end
plugin.set_plugins_meta_parent(service.value.plugins, service)
diff --git a/t/router/radixtree-host-uri3.t b/t/router/radixtree-host-uri3.t
index 0d57788a2..575ab86cb 100644
--- a/t/router/radixtree-host-uri3.t
+++ b/t/router/radixtree-host-uri3.t
@@ -353,3 +353,67 @@ Host: foo.com
qr/func\(\): matched host: [^,]+/
--- grep_error_log_out
func(): matched host: *.com
+
+
+
+=== TEST 10: hosts in services are matched case-insensitively
+--- config
+ location /t {
+ content_by_lua_block {
+ local http = require "resty.http"
+ local uri = "http://127.0.0.1:" .. ngx.var.server_port
+ .. "/hello"
+ local t = require("lib.test_admin").test
+ local code, body = t('/apisix/admin/services/1',
+ ngx.HTTP_PUT,
+ [[{
+ "hosts": ["MixedCase.com"]
+ }]]
+ )
+
+ if code >= 300 then
+ ngx.status = code
+ ngx.say(body)
+ return
+ end
+
+ local code, body = t('/apisix/admin/routes/1',
+ ngx.HTTP_PUT,
+ [[{
+ "upstream": {
+ "nodes": {
+ "127.0.0.1:1980": 1
+ },
+ "type": "roundrobin"
+ },
+ "service_id": "1",
+ "uri": "/hello"
+ }]]
+ )
+
+ if code >= 300 then
+ ngx.status = code
+ ngx.say(body)
+ return
+ end
+ ngx.sleep(0.1)
+
+ for _, h in ipairs({"MixedCase.com", "mixedcase.com",
"other.com"}) do
+ local httpc = http.new()
+ local res, err = httpc:request_uri(uri, {headers = {Host = h}})
+ if not res then
+ ngx.say(err)
+ return
+ end
+ if res.status == 404 then
+ ngx.say(res.status)
+ else
+ ngx.print(res.body)
+ end
+ end
+ }
+ }
+--- response_body
+hello world
+hello world
+404