alexedwards / scs

HTTP Session Management for Go
MIT License
2.05k stars 165 forks source link

Gin support #135

Closed gandaldf closed 1 year ago

gandaldf commented 2 years ago

Splitted feature from #132

werelord commented 1 year ago

This doesn't work if the final handler in the chain outputs a body to the context; doing so will cause the headers to be written, and the ability to write more headers is lost. For example, adding this line to any of the handlers in the tests:

    r.GET("/put", func(c *gin.Context) {
        sessionManager.Put(c.Request.Context(), "foo", "bar")

        // ADD THIS LINE
        c.JSON(http.StatusOK, gin.H{"foo": "bar"})
    })

will cause the test to fail, as the current adapter tries to write the header after subsequent middleware calls..

Ideally, once you have the token, should write the cookie, and then save the data to the store after subsequent middleware has executed in case store changes happen in subsequent middleware calls...