diff --git a/cache.go b/cache.go index a5116faa..8156c16d 100644 --- a/cache.go +++ b/cache.go @@ -140,3 +140,29 @@ func (c *clientCache) observeResponse(ip string, status int, points int, now tim return cacheResult{score: score} } +func (c *clientCache) behaviorScoreLocked(state *clientState, paths []string) int { + // The heuristic is intentionally weak: visiting a content page first is + // normal for a shared link, so it adds only the configured 15 points. + // It becomes useful in combination with malformed headers or 404 scans. + firstRequest := state.requests == 0 + isContent := false + for _, requestPath := range paths { + if requestPath == "/" || requestPath == "/index.html" { + state.sawHome = true + } + if requestPath == "/favicon.ico" { + state.sawFavicon = true + } + if hasStaticAssetExtension(requestPath) { + state.sawStatic = true + } + if pathMatchesAny(requestPath, c.randomPaths) { + isContent = true + } + } + if firstRequest && isContent && !state.sawHome && !state.sawStatic && !state.sawFavicon { + return c.randomScore + } + return 0 +} +