Skip to content

Commit 3daf71c

Browse files
committed
propagate request context into sockjs session
1 parent 4e63e74 commit 3daf71c

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

sockjs/session.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package sockjs
22

33
import (
4+
"context"
45
"errors"
56
"net/http"
67
"sync"
@@ -216,3 +217,10 @@ func (s *session) GetSessionState() SessionState {
216217
func (s *session) Request() *http.Request {
217218
return s.req
218219
}
220+
221+
func (s *session) Context() context.Context {
222+
if s.req != nil {
223+
return s.req.Context()
224+
}
225+
return nil
226+
}

sockjs/sockjs.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package sockjs
22

3-
import "net/http"
3+
import (
4+
"context"
5+
"net/http"
6+
)
47

58
// Session represents a connection between server and client.
69
type Session interface {
@@ -16,4 +19,6 @@ type Session interface {
1619
Close(status uint32, reason string) error
1720
//Gets the state of the session. SessionOpening/SessionActive/SessionClosing/SessionClosed;
1821
GetSessionState() SessionState
22+
// Context returns the session context (derived from the HTTP request)
23+
Context() context.Context
1924
}

0 commit comments

Comments
 (0)