From 5a78bda7ea71e5169c4a4c6a4fcce1d3bc8599cd Mon Sep 17 00:00:00 2001 From: wusphinx Date: Wed, 30 Dec 2020 19:23:55 +0800 Subject: [PATCH] get remote ip by SplitHostPort (#673) Co-authored-by: wuqunlin --- pkg/net/http/blademaster/metadata.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkg/net/http/blademaster/metadata.go b/pkg/net/http/blademaster/metadata.go index fc294a3d3..5befddd5f 100644 --- a/pkg/net/http/blademaster/metadata.go +++ b/pkg/net/http/blademaster/metadata.go @@ -2,6 +2,7 @@ package blademaster import ( "fmt" + "net" "net/http" "strconv" "strings" @@ -110,7 +111,7 @@ func remoteIP(req *http.Request) (remote string) { if remote = req.Header.Get("X-Real-IP"); remote != "" { return } - remote = req.RemoteAddr[:strings.Index(req.RemoteAddr, ":")] + remote, _, _ = net.SplitHostPort(req.RemoteAddr) return }