- Added $remote_ip to remote port number from remote address
This commit is contained in:
Toby Chui 2025-04-07 20:02:04 +08:00
parent ca7cd0476c
commit b863a9720f

View File

@ -2,6 +2,7 @@ package rewrite
import (
"fmt"
"net"
"net/http"
"strings"
)
@ -14,6 +15,11 @@ func GetHeaderVariableValuesFromRequest(r *http.Request) map[string]string {
// Request-specific variables
vars["$host"] = r.Host
vars["$remote_addr"] = r.RemoteAddr
remoteIP, _, err := net.SplitHostPort(r.RemoteAddr)
if err != nil {
remoteIP = r.RemoteAddr // Fallback to the full RemoteAddr if parsing fails
}
vars["$remote_ip"] = remoteIP
vars["$request_uri"] = r.RequestURI
vars["$request_method"] = r.Method
vars["$content_length"] = fmt.Sprintf("%d", r.ContentLength)