From 5b9220561193c60ca9f79d99d09e1820f1d0370a Mon Sep 17 00:00:00 2001 From: hoelee Date: Wed, 14 Jan 2026 08:51:00 +0800 Subject: [PATCH] feat(botfilter): add requestPaths --- util.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/util.go b/util.go index 1b512af8..3e2ca885 100644 --- a/util.go +++ b/util.go @@ -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 +} +