feat(botfilter): add requestPaths
This commit is contained in:
1 parent
cc326c1736
commit
5b92205611
1 file changed
+21
@@ -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
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user