diff --git a/sockjs/session.go b/sockjs/session.go index 7582d43..d1dd680 100644 --- a/sockjs/session.go +++ b/sockjs/session.go @@ -1,6 +1,7 @@ package sockjs import ( + "context" "errors" "net/http" "sync" @@ -216,3 +217,10 @@ func (s *session) GetSessionState() SessionState { func (s *session) Request() *http.Request { return s.req } + +func (s *session) Context() context.Context { + if s.req != nil { + return s.req.Context() + } + return nil +} diff --git a/sockjs/sockjs.go b/sockjs/sockjs.go index 5c2805a..4d51345 100644 --- a/sockjs/sockjs.go +++ b/sockjs/sockjs.go @@ -1,6 +1,9 @@ package sockjs -import "net/http" +import ( + "context" + "net/http" +) // Session represents a connection between server and client. type Session interface { @@ -16,4 +19,6 @@ type Session interface { Close(status uint32, reason string) error //Gets the state of the session. SessionOpening/SessionActive/SessionClosing/SessionClosed; GetSessionState() SessionState + // Context returns the session context (derived from the HTTP request) + Context() context.Context }