From 53c6992ef6b2f653fde397f3660142922077dbf0 Mon Sep 17 00:00:00 2001 From: minoplhy Date: Thu, 11 Apr 2024 22:29:42 +0700 Subject: [PATCH] add: comment on X-Real-IP --- main.go | 2 ++ src/handler/net.go | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 5a9e6a5..0bc9550 100644 --- a/main.go +++ b/main.go @@ -90,6 +90,7 @@ func uploadHandler(w http.ResponseWriter, r *http.Request) { "Content-Type": "application/json", } + // Check if client sent X-Real-IP Header if r.Header.Get("X-Real-IP") != "" && handler.IsInternalIP(r.RemoteAddr) { UploadHeaders["X-Real-IP"] = r.Header.Get("X-Real-IP") } @@ -134,6 +135,7 @@ func uploadHandler(w http.ResponseWriter, r *http.Request) { "Content-Type": "application/json", } + // Check if client sent X-Real-IP Header if r.Header.Get("X-Real-IP") != "" && handler.IsInternalIP(r.RemoteAddr) { ProcessHeaders["X-Real-IP"] = r.Header.Get("X-Real-IP") } diff --git a/src/handler/net.go b/src/handler/net.go index 518505c..8f9fb8b 100644 --- a/src/handler/net.go +++ b/src/handler/net.go @@ -5,8 +5,8 @@ import ( "strings" ) +// Check if request IP Address is in internal ranges func IsInternalIP(ip string) bool { - parts := strings.Split(ip, ":") ip = parts[0]