@@ -160,7 +160,7 @@ func (e HttpConnectionError) Error() string {
160
160
161
161
// ---------------------- SERVER ----------------------
162
162
163
- type CheckClientHandler func (id string , r * http.Request ) bool
163
+ type CheckClientHandler func (id string , r * http.Request ) ( string , bool )
164
164
165
165
// WsServer defines a websocket server, which passively listens for incoming connections on ws or wss protocol.
166
166
// The offered API are of asynchronous nature, and each incoming connection/message is handled using callbacks.
@@ -249,7 +249,7 @@ type WsServer interface {
249
249
SetCheckOriginHandler (handler func (r * http.Request ) bool )
250
250
// SetCheckClientHandler sets a handler for validate incoming websocket connections, allowing to perform
251
251
// 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 ) )
253
253
// Addr gives the address on which the server is listening, useful if, for
254
254
// example, the port is system-defined (set to 0).
255
255
Addr () * net.TCPAddr
@@ -262,7 +262,7 @@ type Server struct {
262
262
connections map [string ]* WebSocket
263
263
httpServer * http.Server
264
264
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 )
266
266
newClientHandler func (ws Channel )
267
267
disconnectedHandler func (ws Channel )
268
268
basicAuthHandler func (username string , password string ) bool
@@ -319,7 +319,7 @@ func (server *Server) SetMessageHandler(handler func(ws Channel, data []byte) er
319
319
server .messageHandler = handler
320
320
}
321
321
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 ) ) {
323
323
server .checkClientHandler = handler
324
324
}
325
325
@@ -502,12 +502,15 @@ out:
502
502
}
503
503
504
504
if server .checkClientHandler != nil {
505
- ok := server .checkClientHandler (id , r )
505
+ newId , ok := server .checkClientHandler (id , r )
506
506
if ! ok {
507
507
server .error (fmt .Errorf ("client validation: invalid client" ))
508
508
http .Error (w , "Unauthorized" , http .StatusUnauthorized )
509
509
return
510
510
}
511
+ if len (newId ) > 0 {
512
+ id = newId
513
+ }
511
514
}
512
515
513
516
// Upgrade websocket
0 commit comments