Skip to content

Commit f0fd711

Browse files
committed
fix:修复路径匹配BUG
1 parent ce741fe commit f0fd711

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

request_handler.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -399,12 +399,14 @@ func makeAdvanceRequest(pathAll string) (*HTTPResponse, error) {
399399
// 遍历配置列表,查找匹配的路径
400400
for _, config := range advanceConfig.PathList {
401401
for _, pathPattern := range config.Paths {
402-
match, err := regexp.MatchString(pathPattern, pathAll)
402+
match, err := regexp.MatchString("^"+pathPattern+"/", pathAll)
403403
if err != nil {
404404
return nil, fmt.Errorf("正则表达式匹配失败: %v", err)
405405
}
406-
pathAll = strings.Replace(pathAll, pathPattern, "", 1)
407406
if match {
407+
re := regexp.MustCompile("^([^/]+)/")
408+
pathAll = re.ReplaceAllString(pathAll, "")
409+
pathAll = "/" + pathAll
408410
// 并发请求多个URL,返回最快的响应
409411
responses := make(chan *HTTPResponse, len(config.URL))
410412
errors := make(chan error, len(config.URL))

0 commit comments

Comments
 (0)