@@ -160,7 +160,7 @@ func (e HttpConnectionError) Error() string {
160160
161161// ---------------------- SERVER ----------------------
162162
163- type CheckClientHandler func (id string , r * http.Request ) bool
163+ type CheckClientHandler func (id string , r * http.Request ) ( string , bool )
164164
165165// WsServer defines a websocket server, which passively listens for incoming connections on ws or wss protocol.
166166// The offered API are of asynchronous nature, and each incoming connection/message is handled using callbacks.
@@ -249,7 +249,7 @@ type WsServer interface {
249249 SetCheckOriginHandler (handler func (r * http.Request ) bool )
250250 // SetCheckClientHandler sets a handler for validate incoming websocket connections, allowing to perform
251251 // custom client connection checks.
252- SetCheckClientHandler (handler func (id string , r * http.Request ) bool )
252+ SetCheckClientHandler (handler func (id string , r * http.Request ) ( string , bool ) )
253253 // Addr gives the address on which the server is listening, useful if, for
254254 // example, the port is system-defined (set to 0).
255255 Addr () * net.TCPAddr
@@ -262,7 +262,7 @@ type Server struct {
262262 connections map [string ]* WebSocket
263263 httpServer * http.Server
264264 messageHandler func (ws Channel , data []byte ) error
265- checkClientHandler func (id string , r * http.Request ) bool
265+ checkClientHandler func (id string , r * http.Request ) ( string , bool )
266266 newClientHandler func (ws Channel )
267267 disconnectedHandler func (ws Channel )
268268 basicAuthHandler func (username string , password string ) bool
@@ -319,7 +319,7 @@ func (server *Server) SetMessageHandler(handler func(ws Channel, data []byte) er
319319 server .messageHandler = handler
320320}
321321
322- func (server * Server ) SetCheckClientHandler (handler func (id string , r * http.Request ) bool ) {
322+ func (server * Server ) SetCheckClientHandler (handler func (id string , r * http.Request ) ( string , bool ) ) {
323323 server .checkClientHandler = handler
324324}
325325
@@ -502,12 +502,15 @@ out:
502502 }
503503
504504 if server .checkClientHandler != nil {
505- ok := server .checkClientHandler (id , r )
505+ newId , ok := server .checkClientHandler (id , r )
506506 if ! ok {
507507 server .error (fmt .Errorf ("client validation: invalid client" ))
508508 http .Error (w , "Unauthorized" , http .StatusUnauthorized )
509509 return
510510 }
511+ if len (newId ) > 0 {
512+ id = newId
513+ }
511514 }
512515
513516 // Upgrade websocket
0 commit comments