Skip to content

Commit

Permalink
refactor: Removing double log when error
Browse files Browse the repository at this point in the history
Signed-off-by: Vincent Boutour <[email protected]>
  • Loading branch information
ViBiOh committed Jan 13, 2024
1 parent e317a37 commit 645a5f7
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 22 deletions.
7 changes: 0 additions & 7 deletions pkg/fibr/fibr.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"errors"
"fmt"
"log/slog"
"net/http"
"path"
"strings"
Expand Down Expand Up @@ -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)
}

Expand All @@ -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)
}

Expand Down Expand Up @@ -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))
}
15 changes: 0 additions & 15 deletions pkg/provider/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}

0 comments on commit 645a5f7

Please sign in to comment.