From 645a5f723e5ffd2e476b59f0157f63b4a35b2f98 Mon Sep 17 00:00:00 2001 From: Vincent Boutour Date: Sat, 13 Jan 2024 10:42:01 +0100 Subject: [PATCH] refactor: Removing double log when error Signed-off-by: Vincent Boutour --- pkg/fibr/fibr.go | 7 ------- pkg/provider/request.go | 15 --------------- 2 files changed, 22 deletions(-) diff --git a/pkg/fibr/fibr.go b/pkg/fibr/fibr.go index be8b2d94..70635d71 100644 --- a/pkg/fibr/fibr.go +++ b/pkg/fibr/fibr.go @@ -4,7 +4,6 @@ import ( "context" "errors" "fmt" - "log/slog" "net/http" "path" "strings" @@ -55,7 +54,6 @@ func (s Service) parseRequest(r *http.Request) (provider.Request, error) { } if err := s.parseShare(r.Context(), &request, r.Header.Get("Authorization")); err != nil { - logRequest(r) return request, model.WrapUnauthorized(err) } @@ -79,7 +77,6 @@ func (s Service) parseRequest(r *http.Request) (provider.Request, error) { _, user, err := s.login.IsAuthenticated(r) if err != nil { - logRequest(r) return request, convertAuthenticationError(err) } @@ -138,7 +135,3 @@ func convertAuthenticationError(err error) error { return model.WrapUnauthorized(err) } - -func logRequest(r *http.Request) { - slog.WarnContext(r.Context(), "Unauthenticated request", "method", r.Method, "url", r.URL.String(), "ip", provider.GetIP(r)) -} diff --git a/pkg/provider/request.go b/pkg/provider/request.go index 80c847c0..758a67bf 100644 --- a/pkg/provider/request.go +++ b/pkg/provider/request.go @@ -21,11 +21,6 @@ var ( LayoutPathsCookieName = "layout_paths" preferencesPathSeparator = "|" - ipHeaders = []string{ - "Cf-Connecting-Ip", - "X-Forwarded-For", - "X-Real-Ip", - } ) func ParseDisplay(input string) Display { @@ -249,13 +244,3 @@ func SetPrefsCookie(w http.ResponseWriter, request Request) { w.Header().Add("content-language", "en") } - -func GetIP(r *http.Request) string { - for _, header := range ipHeaders { - if ip := r.Header.Get(header); len(ip) != 0 { - return ip - } - } - - return r.RemoteAddr -}