package botfilter import ( "net/http" "strings" ) type matchResult struct { points int forceBan bool reason string } func inspectRequest(r *http.Request, cfg *compiledConfig) matchResult { paths := requestPaths(r) userAgent := strings.TrimSpace(r.UserAgent()) if cfg.RequireUserAgent && userAgent == "" { return matchResult{points: cfg.EmptyUserAgentScore, forceBan: true, reason: "missing user-agent"} } if cfg.RequireAccept && !hasHeader(r, "Accept") { return matchResult{points: cfg.MissingAcceptScore, forceBan: true, reason: "missing accept"} } if cfg.RequireHost && strings.TrimSpace(r.Host) == "" { return matchResult{forceBan: true, reason: "missing host"} } if containsToken(strings.ToLower(userAgent), cfg.blockedAgents) { return matchResult{points: cfg.BlockedUserAgentScore, forceBan: true, reason: "blocked user-agent"} } if matchesBlockedPath(paths, cfg.blockedPaths) { return matchResult{points: cfg.BadPathScore, forceBan: true, reason: "blocked path"} } if matchesBlockedExtension(paths, cfg.blockedExts) { return matchResult{points: cfg.BadPathScore, forceBan: true, reason: "blocked extension"} }