feat(botfilter): add botFilter.ServeHTTP
This commit is contained in:
1 parent
060bdff85f
commit
9fe86bc379
1 file changed
+13
@@ -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
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user