Skip to content

Commit 80078ae

Browse files
fix: only measure time to check and not web server responce
1 parent 93a0491 commit 80078ae

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

botblocker.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,31 +184,35 @@ func (b *BotBlocker) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
184184
log.Debugf("Checking request: CIDR: \"%v\" user agent: \"%s\"", req.RemoteAddr, req.UserAgent())
185185
// Using an external plugin to avoid https://github.com/traefik/yaegi/issues/1697
186186
timer := getTimer(startTime)
187-
defer timer()
188187

189188
remoteAddrPort, err := netip.ParseAddrPort(req.RemoteAddr)
190189
if err != nil {
190+
timer()
191191
http.Error(rw, "internal error", http.StatusInternalServerError)
192192
return
193193
}
194194
if b.shouldBlockIp(remoteAddrPort.Addr()) {
195195
log.Infof("blocked request with from IP \"%v\"", remoteAddrPort.Addr())
196+
timer()
196197
http.Error(rw, "blocked", http.StatusForbidden)
197198
return
198199
}
199200

200201
agent := strings.ToLower(req.UserAgent())
201202
blocked, badAgent, err := b.shouldBlockAgent(agent)
202203
if err != nil {
204+
timer()
203205
http.Error(rw, "internal error", http.StatusInternalServerError)
204206
return
205207
}
206208
if blocked {
207209
log.Infof("blocked request with user agent \"%v\" because it contained \"%v\"", agent, badAgent)
210+
timer()
208211
http.Error(rw, "blocked", http.StatusForbidden)
209212
return
210213
}
211214

215+
timer()
212216
b.next.ServeHTTP(rw, req)
213217
}
214218

0 commit comments

Comments
 (0)