@@ -27,14 +27,8 @@ var _ sessions.SessionStore = &SessionStore{}
27// SessionStore is an implementation of the sessions.SessionStore
27// SessionStore is an implementation of the sessions.SessionStore
28// interface that stores sessions in client side cookies
28// interface that stores sessions in client side cookies
29type SessionStore struct {
29type SessionStore struct {
30+ CookieOptions *options.CookieOptions
30− CookieCipher *cookie.Cipher
31+ CookieCipher *cookie.Cipher
32− CookieExpire time.Duration
40// Save takes a sessions.SessionState and stores the information from it
34// Save takes a sessions.SessionState and stores the information from it
@@ -54,12 +48,12 @@ func (s *SessionStore) Save(rw http.ResponseWriter, req *http.Request, ss *sessi
54// Load reads sessions.SessionState information from Cookies within the
48// Load reads sessions.SessionState information from Cookies within the
55// HTTP request object
49// HTTP request object
56func (s *SessionStore) Load(req *http.Request) (*sessions.SessionState, error) {
50func (s *SessionStore) Load(req *http.Request) (*sessions.SessionState, error) {
57− c, err := loadCookie(req, s.CookieName)
51+ c, err := loadCookie(req, s.CookieOptions.CookieName)
58 if err != nil {
52 if err != nil {
59 // always http.ErrNoCookie
53 // always http.ErrNoCookie
60− return nil, fmt.Errorf("Cookie %q not present", s.CookieName)
54+ return nil, fmt.Errorf("Cookie %q not present", s.CookieOptions.CookieName)
62− val, _, ok := cookie.Validate(c, s.CookieSecret, s.CookieExpire)
56+ val, _, ok := cookie.Validate(c, s.CookieOptions.CookieSecret, s.CookieOptions.CookieExpire)
64 return nil, errors.New("Cookie Signature not valid")
58 return nil, errors.New("Cookie Signature not valid")
@@ -77,7 +71,7 @@ func (s *SessionStore) Clear(rw http.ResponseWriter, req *http.Request) error {
77 var cookies []*http.Cookie
71 var cookies []*http.Cookie
79 // matches CookieName, CookieName_<number>
73 // matches CookieName, CookieName_<number>
80− var cookieNameRegex = regexp.MustCompile(fmt.Sprintf("^%s(_\\d+)?$", s.CookieName))
74+ var cookieNameRegex = regexp.MustCompile(fmt.Sprintf("^%s(_\\d+)?$", s.CookieOptions.CookieName))
82 for _, c := range req.Cookies() {
76 for _, c := range req.Cookies() {
83 if cookieNameRegex.MatchString(c.Name) {
77 if cookieNameRegex.MatchString(c.Name) {
@@ -93,33 +87,30 @@ func (s *SessionStore) Clear(rw http.ResponseWriter, req *http.Request) error {
94// setSessionCookie adds the user's session cookie to the response
88// setSessionCookie adds the user's session cookie to the response
95func (s *SessionStore) setSessionCookie(rw http.ResponseWriter, req *http.Request, val string, created time.Time) {
89func (s *SessionStore) setSessionCookie(rw http.ResponseWriter, req *http.Request, val string, created time.Time) {
96− for _, c := range s.makeSessionCookie(req, val, s.CookieExpire, created) {
90+ for _, c := range s.makeSessionCookie(req, val, created) {
97 http.SetCookie(rw, c)
91 http.SetCookie(rw, c)
101// makeSessionCookie creates an http.Cookie containing the authenticated user's
95// makeSessionCookie creates an http.Cookie containing the authenticated user's
102// authentication details
96// authentication details
103−func (s *SessionStore) makeSessionCookie(req *http.Request, value string, expiration time.Duration, now time.Time) []*http.Cookie {
97+func (s *SessionStore) makeSessionCookie(req *http.Request, value string, now time.Time) []*http.Cookie {
104 if value != "" {
98 if value != "" {
105− value = cookie.SignedValue(s.CookieSecret, s.CookieName, value, now)
99+ value = cookie.SignedValue(s.CookieOptions.CookieSecret, s.CookieOptions.CookieName, value, now)
107− c := s.makeCookie(req, s.CookieName, value, expiration, now)
101+ c := s.makeCookie(req, s.CookieOptions.CookieName, value, s.CookieOptions.CookieExpire, now)
108− if len(c.Value) > 4096-len(s.CookieName) {
102+ if len(c.Value) > 4096-len(s.CookieOptions.CookieName) {
109 return splitCookie(c)
103 return splitCookie(c)
111 return []*http.Cookie{c}
105 return []*http.Cookie{c}
114func (s *SessionStore) makeCookie(req *http.Request, name string, value string, expiration time.Duration, now time.Time) *http.Cookie {
108func (s *SessionStore) makeCookie(req *http.Request, name string, value string, expiration time.Duration, now time.Time) *http.Cookie {
115− return cookies.MakeCookie(
109+ return cookies.MakeCookieFromOptions(
119− s.CookiePath,
113+ s.CookieOptions,
123 expiration,
114 expiration,
@@ -138,14 +129,8 @@ func NewCookieSessionStore(opts options.CookieStoreOptions, cookieOpts *options.
140 return &SessionStore{
131 return &SessionStore{
141− CookieCipher: cipher,
132+ CookieCipher: cipher,
142− CookieDomain: cookieOpts.CookieDomain,
133+ CookieOptions: cookieOpts,
143− CookieExpire: cookieOpts.CookieExpire,
144− CookieHTTPOnly: cookieOpts.CookieHTTPOnly,
145− CookieName: cookieOpts.CookieName,
146− CookiePath: cookieOpts.CookiePath,
147− CookieSecret: cookieOpts.CookieSecret,
148− CookieSecure: cookieOpts.CookieSecure,