Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions cgi.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,20 @@ func addKnownVariablesToServer(fc *frankenPHPContext, trackVarsArray *C.zval) {
request := fc.request
// Separate remote IP and port; more lenient than net.SplitHostPort
var ip, port string
if idx := strings.LastIndex(request.RemoteAddr, ":"); idx > -1 {
ip = request.RemoteAddr[:idx]
port = request.RemoteAddr[idx+1:]
remoteAddr := request.RemoteAddr

// When using a UNIX domain socket, Go's net/http sets RemoteAddr to "@"
// (see https://github.com/golang/go/issues/49825). In this case, fall
// back to 127.0.0.1 as the remote address, which matches the convention
// used by Apache httpd and other web servers when listening on UNIX sockets.
if remoteAddr == "@" {
ip = "127.0.0.1"
port = ""
} else if idx := strings.LastIndex(remoteAddr, ":"); idx > -1 {
ip = remoteAddr[:idx]
port = remoteAddr[idx+1:]
} else {
ip = request.RemoteAddr
ip = remoteAddr
}

// Remove [] from IPv6 addresses
Expand Down
Loading