Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ require (
github.com/denisenkom/go-mssqldb v0.0.0-20190724012636-11b2859924c1
github.com/go-sql-driver/mysql v1.4.1
github.com/go-xorm/xorm v0.7.4
github.com/gorilla/context v1.1.1
github.com/gorilla/securecookie v1.1.1
github.com/gorilla/sessions v0.0.0-20160922145804-ca9ada445741
github.com/lib/pq v1.0.0
Expand Down
13 changes: 9 additions & 4 deletions xormstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ For API to use in HTTP handlers see https://github.com/gorilla/sessions
package xormstore

import (
"context"
"encoding/base32"
"net/http"
"strings"
Expand All @@ -45,7 +46,6 @@ import (
"github.com/lafriks/xormstore/util"

"github.com/go-xorm/xorm"
"github.com/gorilla/context"
"github.com/gorilla/securecookie"
"github.com/gorilla/sessions"
)
Expand Down Expand Up @@ -141,15 +141,17 @@ func (st *Store) New(r *http.Request, name string) (*sessions.Session, error) {
return session, nil
}

context.Set(r, contextKey(name), s)
//Add data to context
ctx := context.WithValue(r.Context(), contextKey(name), s)
r = r.WithContext(ctx) //Set context //TODO validate this or should be *r = *(r.WithContext(ctx))
}

return session, nil
}

// Save session and set cookie header
func (st *Store) Save(r *http.Request, w http.ResponseWriter, session *sessions.Session) error {
s, _ := context.Get(r, contextKey(session.Name())).(*xormSession)
s, _ := r.Context().Value(contextKey(session.Name())).(*xormSession)

// delete if max age is < 0
if session.Options.MaxAge < 0 {
Expand Down Expand Up @@ -188,7 +190,10 @@ func (st *Store) Save(r *http.Request, w http.ResponseWriter, session *sessions.
if _, err := st.e.Insert(s); err != nil {
return err
}
context.Set(r, contextKey(session.Name()), s)
//Add data to context
ctx := context.WithValue(r.Context(), contextKey(session.Name()), s)
r = r.WithContext(ctx) //Set context //TODO validate this or should be *r = *(r.WithContext(ctx))

} else {
s.Data = data
s.UpdatedUnix = now
Expand Down