Skip to content

Commit 9151a01

Browse files
committed
add customID to the Upgrade method so Iris side can do its magic to set a custom ID Generator as requested at: #1 (comment)
1 parent 1837ea3 commit 9151a01

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

server.go

+15-4
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,14 @@ func IsTryingToReconnect(err error) (ok bool) {
198198
const websocketReconectHeaderKey = "X-Websocket-Reconnect"
199199

200200
// Upgrade handles the connection, same as `ServeHTTP` but it can accept
201-
// a socket wrapper and it does return the connection or any errors.
202-
func (s *Server) Upgrade(w http.ResponseWriter, r *http.Request, socketWrapper func(Socket) Socket) (*Conn, error) {
201+
// a socket wrapper and a "customID" that overrides the server's IDGenerator
202+
// and it does return the connection or any errors.
203+
func (s *Server) Upgrade(
204+
w http.ResponseWriter,
205+
r *http.Request,
206+
socketWrapper func(Socket) Socket,
207+
customID string,
208+
) (*Conn, error) {
203209
if atomic.LoadUint32(&s.closed) > 0 {
204210
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
205211
return nil, errServerClosed
@@ -237,7 +243,12 @@ func (s *Server) Upgrade(w http.ResponseWriter, r *http.Request, socketWrapper f
237243
}
238244

239245
c := newConn(socket, s.namespaces)
240-
c.id = s.IDGenerator(w, r)
246+
if customID != "" {
247+
c.id = customID
248+
} else {
249+
c.id = s.IDGenerator(w, r)
250+
}
251+
241252
c.readTimeout = s.readTimeout
242253
c.writeTimeout = s.writeTimeout
243254
c.server = s
@@ -298,7 +309,7 @@ func (s *Server) Upgrade(w http.ResponseWriter, r *http.Request, socketWrapper f
298309
// ServeHTTP completes the `http.Handler` interface, it should be passed on a http server's router
299310
// to serve this neffos server on a specific endpoint.
300311
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
301-
s.Upgrade(w, r, nil)
312+
s.Upgrade(w, r, nil, "")
302313
}
303314

304315
func (s *Server) waitMessage(c *Conn) bool {

0 commit comments

Comments
 (0)