From 563494cb7779a840bd650f0cf215b6e6ae7080ed Mon Sep 17 00:00:00 2001 From: Anhgelus Morhtuuzh Date: Fri, 26 Dec 2025 23:15:06 +0100 Subject: feat(backend): introduce rate limit to protect auth --- backend/logger.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'backend/logger.go') diff --git a/backend/logger.go b/backend/logger.go index da5fadb..f3dbc3c 100644 --- a/backend/logger.go +++ b/backend/logger.go @@ -24,10 +24,11 @@ type customWriter struct { } func (c *customWriter) WriteHeader(statusCode int) { - c.statusCode = statusCode - if statusCode != c.statusCode { - c.ResponseWriter.WriteHeader(statusCode) + if statusCode == c.statusCode { + return } + c.statusCode = statusCode + c.ResponseWriter.WriteHeader(statusCode) } func GetStatusCode(ctx context.Context) func() int { @@ -58,7 +59,7 @@ func SetLogger(l *slog.Logger) func(http.Handler) http.Handler { next.ServeHTTP(ww, r.WithContext(ctx)) - if ww.statusCode == http.StatusNotFound { + if ww.statusCode == http.StatusNotFound || ww.statusCode == http.StatusTooManyRequests { return } var lvl slog.Level -- cgit v1.2.3