diff --git a/server/conn.go b/server/conn.go index 62ba494..8a2c7e8 100644 --- a/server/conn.go +++ b/server/conn.go @@ -9,14 +9,18 @@ import ( "github.com/kercylan98/minotaur/utils/concurrent" "github.com/kercylan98/minotaur/utils/hash" "github.com/kercylan98/minotaur/utils/log" + "github.com/kercylan98/minotaur/utils/random" "github.com/panjf2000/gnet" "github.com/xtaci/kcp-go/v5" "net" + "net/http" "runtime/debug" "strings" "sync" ) +var wsRequestKey = fmt.Sprintf("WS:REQ:%s", strings.ToUpper(random.HostName())) + // newKcpConn 创建一个处理KCP的连接 func newKcpConn(server *Server, session *kcp.UDPSession) *Conn { c := &Conn{ @@ -123,6 +127,11 @@ type connection struct { mu sync.Mutex } +// GetWebsocketRequest 获取websocket请求 +func (slf *Conn) GetWebsocketRequest() *http.Request { + return slf.GetData(wsRequestKey).(*http.Request) +} + // IsEmpty 是否是空连接 func (slf *Conn) IsEmpty() bool { return slf.ws == nil && slf.gn == nil && slf.kcp == nil && slf.gw == nil diff --git a/server/server.go b/server/server.go index 1e882eb..1ce45cf 100644 --- a/server/server.go +++ b/server/server.go @@ -299,6 +299,7 @@ func (slf *Server) Run(addr string) error { } ws.EnableWriteCompression(slf.websocketWriteCompression) conn := newWebsocketConn(slf, ws, ip) + conn.SetData(wsRequestKey, request) for k, v := range request.URL.Query() { if len(v) == 1 { conn.SetData(k, v[0])