diff options
| author | Anhgelus Morhtuuzh <william@herges.fr> | 2025-12-26 23:15:06 +0100 |
|---|---|---|
| committer | Anhgelus Morhtuuzh <william@herges.fr> | 2025-12-26 23:15:06 +0100 |
| commit | 563494cb7779a840bd650f0cf215b6e6ae7080ed (patch) | |
| tree | 8a2630444cbfbbe6db9c073450467eeb01e028cd /backend/logger.go | |
| parent | af11793ca48244eafd7dcdf66ac1dff83995a775 (diff) | |
feat(backend): introduce rate limit to protect auth
Diffstat (limited to 'backend/logger.go')
| -rw-r--r-- | backend/logger.go | 9 |
1 files changed, 5 insertions, 4 deletions
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 |
