feat(botfilter): add botFilter.ServeHTTP

This commit is contained in:
hoelee committed 2026-05-13 15:40:00 +08:00
1 parent b7c0d09497
commit 71169adae3
1 file changed
+13
+13
View File
@@ -39,3 +39,16 @@ func New(_ context.Context, next http.Handler, config *Config, name string) (htt
}, nil
}
func (b *botFilter) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
now := time.Now()
addr := clientIP(r, b.config)
ip := addressString(addr)
if addressInPrefixes(addr, b.config.whitelist) {
b.next.ServeHTTP(rw, r)
return
}
if existing := b.cache.isBanned(ip, now); existing.banned {
b.reject(rw, ip, "temporary ban", existing)
return
}