From 51931c49ff4142a80ab4430951ca6f0fbcb04810 Mon Sep 17 00:00:00 2001 From: hoelee Date: Wed, 20 May 2026 12:19:00 +0800 Subject: [PATCH] feat(botfilter): add botFilter.reject --- botfilter.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/botfilter.go b/botfilter.go index e941451a..14f530da 100644 --- a/botfilter.go +++ b/botfilter.go @@ -76,3 +76,18 @@ func (b *botFilter) ServeHTTP(rw http.ResponseWriter, r *http.Request) { } } +func (b *botFilter) reject(rw http.ResponseWriter, ip, reason string, decision cacheResult) { + b.logger.blocked(ip, reason, decision.score) + rw.Header().Set("Cache-Control", "no-store") + rw.Header().Set("Content-Type", "text/plain; charset=utf-8") + if decision.banUntil.After(time.Now()) { + seconds := int(time.Until(decision.banUntil).Seconds()) + if seconds < 1 { + seconds = 1 + } + rw.Header().Set("Retry-After", strconv.Itoa(seconds)) + } + rw.WriteHeader(b.config.StatusCode) + _, _ = io.WriteString(rw, "request denied\n") +} +