Skip to content

Commit

Permalink
revert
Browse files Browse the repository at this point in the history
  • Loading branch information
PlusOne committed Feb 13, 2025
1 parent 2427bff commit f00507d
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -1646,13 +1646,13 @@ func (p *WorkerPool) Shutdown() {
}

func handleRequest(w http.ResponseWriter, r *http.Request) {
ips := getClientIPs(r)
for _, ip := range ips {
log.WithFields(logrus.Fields{
"client_ip": ip,
"version": detectIPVersion(ip),
}).Info("Incoming request")
}
clientIP := getOriginalClientIP(r)
log.WithFields(logrus.Fields{
"method": r.Method,
"url": r.URL.String(),
"remote": clientIP,
}).Info("Incoming request")

if r.Method == http.MethodPost && strings.Contains(r.Header.Get("Content-Type"), "multipart/form-data") {
absFilename, err := sanitizeFilePath(conf.Server.StoragePath, strings.TrimPrefix(r.URL.Path, "/"))
if err != nil {
Expand All @@ -1670,7 +1670,7 @@ func handleRequest(w http.ResponseWriter, r *http.Request) {
return
}

clientIP := r.Header.Get("X-Real-IP")
clientIP = r.Header.Get("X-Real-IP")
if clientIP == "" {
clientIP = r.Header.Get("X-Forwarded-For")
}
Expand Down Expand Up @@ -2792,3 +2792,15 @@ func detectIPVersion(ip string) string {
}
return "IPv4"
}

func getOriginalClientIP(r *http.Request) string {
if ip := r.Header.Get("X-Forwarded-For"); ip != "" {
parts := strings.Split(ip, ",")
return strings.TrimSpace(parts[0])
}
if ip := r.Header.Get("X-Real-IP"); ip != "" {
return strings.TrimSpace(ip)
}
host, _, _ := net.SplitHostPort(r.RemoteAddr)
return host
}

0 comments on commit f00507d

Please sign in to comment.