feat(botfilter): add botFilter.reject
This commit is contained in:
1 parent
25dfbde1de
commit
982e76179d
1 file changed
+15
@@ -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")
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user