From 48cbc55d75c16cce6d8138b679655317a8de71d4 Mon Sep 17 00:00:00 2001 From: GoEdgeLab Date: Fri, 25 Aug 2023 15:04:18 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0${serverAddr}=E5=8F=98?= =?UTF-8?q?=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/nodes/http_request.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/internal/nodes/http_request.go b/internal/nodes/http_request.go index 0c25299..da5c1fb 100644 --- a/internal/nodes/http_request.go +++ b/internal/nodes/http_request.go @@ -854,6 +854,18 @@ func (this *HTTPRequest) Format(source string) string { return this.requestHeadersString() case "serverName": return this.ServerName + case "serverAddr": + var requestConn = this.RawReq.Context().Value(HTTPConnContextKey) + if requestConn != nil { + conn, ok := requestConn.(net.Conn) + if ok { + host, _, _ := net.SplitHostPort(conn.LocalAddr().String()) + if len(host) > 0 { + return host + } + } + } + return "" case "serverPort": return strconv.Itoa(this.requestServerPort()) case "hostname":