fix(server): 修复URL主机匹配逻辑并添加测试用例

服务器管理器中的makeMatcher函数现在仅检查URL.Host而不是同时检查req.Host和req.URL.Host,
这解决了无效类型请求的处理问题。同时为strings模块添加了新的测试用例以验证前缀匹配功能,
包括对无效类型输入的测试场景。
```
This commit is contained in:
程广 2026-07-13 09:49:34 +08:00
parent 50c48e8f07
commit 8d79647018
2 changed files with 8 additions and 1 deletions

View File

@ -69,6 +69,12 @@ func TestStrings_HasOrContainPrefix(t *testing.T) {
value: "a", value: "a",
want: true, want: true,
}, },
{
name: "invalid type",
input: `"git.kingecg.top"`,
value: "www.o69iay0p.o69iay0p.wwwgit.kingecg.top/kingecg/rustlings/blame/commit/3bcea675ccac7c58cbdf5775c51ea8097fa57c8c/.idea/rustlings.iml",
want: false,
},
} }
for _, tt := range tests { for _, tt := range tests {
s := &Strings{} s := &Strings{}

View File

@ -28,7 +28,8 @@ func makeMatcher(name model.Strings, s *ServerListener) cmux.Matcher {
return false return false
} }
// l.Debug("Request Host:", req.Host, "URL Host:", req.URL.Host, "Name:", name) // l.Debug("Request Host:", req.Host, "URL Host:", req.URL.Host, "Name:", name)
return name.HasOrContainPrefix(req.Host) || name.HasOrContainPrefix(req.URL.Host) //name.HasOrContainPrefix(req.Host) ||
return name.HasOrContainPrefix(req.URL.Host)
} }
} }