Skip to content

Commit

Permalink
modified handler to call options.JSessionID for /info endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
igm committed May 24, 2020
1 parent ca7b4da commit 24280f9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion v3/sockjs/handler.go
Expand Up @@ -38,7 +38,7 @@ func NewHandler(prefix string, opts Options, handlerFunc func(Session)) *Handler
h.mappings = []*mapping{
newMapping("GET", "^[/]?$", welcomeHandler),
newMapping("OPTIONS", "^/info$", opts.cookie, xhrCors, cacheFor, opts.info),
newMapping("GET", "^/info$", xhrCors, noCache, opts.info),
newMapping("GET", "^/info$", opts.cookie, xhrCors, noCache, opts.info),
// XHR
newMapping("POST", sessionPrefix+"/xhr_send$", opts.cookie, xhrCors, noCache, h.xhrSend),
newMapping("OPTIONS", sessionPrefix+"/xhr_send$", opts.cookie, xhrCors, cacheFor, xhrOptions),
Expand Down
8 changes: 7 additions & 1 deletion v3/sockjs/handler_test.go
Expand Up @@ -45,7 +45,12 @@ func TestHandler_Create(t *testing.T) {
}

func TestHandler_RootPrefixInfoHandler(t *testing.T) {
handler := NewHandler("", testOptions, nil)
infoOptions := testOptions
jSessionCalled := false
infoOptions.JSessionID = func(writer http.ResponseWriter, request *http.Request) {
jSessionCalled = true
}
handler := NewHandler("", infoOptions, nil)
if handler.Prefix() != "" {
t.Errorf("Prefix not properly set, got '%s' expected '%s'", handler.Prefix(), "")
}
Expand All @@ -66,6 +71,7 @@ func TestHandler_RootPrefixInfoHandler(t *testing.T) {
t.Errorf("Unexpected status code receiver, got '%d' expected '%d'", resp.StatusCode, http.StatusOK)
t.FailNow()
}
assert.True(t, jSessionCalled)
infoData, err := ioutil.ReadAll(resp.Body)
if err != nil {
t.Errorf("Error reading body: '%v'", err)
Expand Down

0 comments on commit 24280f9

Please sign in to comment.