add ClientAddr for websocket conn

This commit is contained in:
ginuerzh
2024-10-16 20:46:45 +08:00
parent ea179a0ee6
commit 24547b4332
14 changed files with 98 additions and 37 deletions
+6
View File
@@ -19,6 +19,7 @@ import (
"github.com/go-gost/core/recorder"
"github.com/go-gost/core/service"
ctxvalue "github.com/go-gost/x/ctx"
xnet "github.com/go-gost/x/internal/net"
xmetrics "github.com/go-gost/x/metrics"
"github.com/rs/xid"
)
@@ -188,6 +189,11 @@ func (s *defaultService) Serve() error {
}
clientAddr := conn.RemoteAddr().String()
if ca, ok := conn.(xnet.ClientAddr); ok {
if addr := ca.ClientAddr(); addr != nil {
clientAddr = addr.String()
}
}
clientIP := clientAddr
if h, _, _ := net.SplitHostPort(clientAddr); h != "" {
clientIP = h