增加${serverAddr}变量

This commit is contained in:
GoEdgeLab
2023-08-25 15:04:18 +08:00
parent 858bc6b619
commit 48cbc55d75

View File

@@ -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":