From e812b3fcf697d95b940fdb75ff615ba31b0f3d51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=A5=A5=E8=B6=85?= Date: Sun, 8 May 2022 16:56:10 +0800 Subject: [PATCH] =?UTF-8?q?X-Forwarded-For=E4=B8=AD=E5=8C=85=E5=90=AB?= =?UTF-8?q?=E5=BD=93=E5=89=8D=E5=AE=A2=E6=88=B7=E7=AB=AF=E7=9A=84IP?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/nodes/http_request.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/internal/nodes/http_request.go b/internal/nodes/http_request.go index 012e91b..3809b6d 100644 --- a/internal/nodes/http_request.go +++ b/internal/nodes/http_request.go @@ -1047,7 +1047,7 @@ func (this *HTTPRequest) requestRemoteAddr(supportVar bool) string { } // X-Forwarded-For - forwardedFor := this.RawReq.Header.Get("X-Forwarded-For") + var forwardedFor = this.RawReq.Header.Get("X-Forwarded-For") if len(forwardedFor) > 0 { commaIndex := strings.Index(forwardedFor, ",") if commaIndex > 0 { @@ -1461,7 +1461,12 @@ func (this *HTTPRequest) setForwardHeaders(header http.Header) { header["X-Forwarded-For"] = []string{strings.Join(forwardedFor, ", ") + ", " + remoteAddr} } } else { - header["X-Forwarded-For"] = []string{remoteAddr} + var clientRemoteAddr = this.requestRemoteAddr(true) + if len(clientRemoteAddr) > 0 && clientRemoteAddr != remoteAddr { + header["X-Forwarded-For"] = []string{clientRemoteAddr + ", " + remoteAddr} + } else { + header["X-Forwarded-For"] = []string{remoteAddr} + } } }