feat(botfilter): add requestPaths

This commit is contained in:
hoelee committed 2026-01-22 08:51:00 +08:00
1 parent ba324ad660
commit 82adcd573b
1 file changed
+21
+21
View File
@@ -97,3 +97,24 @@ func normalisePath(value string) string {
return strings.ToLower(pathpkg.Clean(value))
}
func requestPaths(r *http.Request) []string {
values := []string{r.URL.Path, r.URL.EscapedPath()}
result := make([]string, 0, len(values)*3)
seen := make(map[string]struct{})
for _, value := range values {
for i := 0; i < 3 && value != ""; i++ {
normalised := normalisePath(value)
if _, ok := seen[normalised]; !ok {
seen[normalised] = struct{}{}
result = append(result, normalised)
}
decoded, err := url.PathUnescape(value)
if err != nil || decoded == value {
break
}
value = decoded
}
}
return result
}