Skip to content

Commit

Permalink
Merge pull request #201 from mem/master
Browse files Browse the repository at this point in the history
Make sure the session expiration information is present in the cookie
  • Loading branch information
robfig committed Jun 30, 2013
2 parents 7dd2f39 + de6b442 commit 501d82c
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions session.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ func getSessionExpiration() time.Time {
// Returns an http.Cookie containing the signed session.
func (s Session) cookie() *http.Cookie {
var sessionValue string
ts := getSessionExpiration()
s[TS_KEY] = getSessionExpirationCookie(ts)
for key, value := range s {
if strings.ContainsAny(key, ":\x00") {
panic("Session keys may not have colons or null bytes")
Expand All @@ -70,7 +72,7 @@ func (s Session) cookie() *http.Cookie {
Name: CookiePrefix + "_SESSION",
Value: Sign(sessionData) + "-" + sessionData,
Path: "/",
Expires: getSessionExpiration().UTC(),
Expires: ts.UTC(),
}
}

Expand Down Expand Up @@ -105,9 +107,8 @@ func getSessionFromCookie(cookie *http.Cookie) Session {
})

if sessionTimeoutExpiredOrMissing(session) {
session = make(map[string]string)
session = make(Session)
}
session[TS_KEY] = strconv.FormatInt(getSessionExpiration().Unix(), 10)

return session
}
Expand All @@ -122,12 +123,15 @@ func SessionFilter(c *Controller, fc []Filter) {
}

func restoreSession(req *http.Request) Session {
session := make(map[string]string)
session := make(Session)
cookie, err := req.Cookie(CookiePrefix + "_SESSION")
if err != nil {
session[TS_KEY] = strconv.FormatInt(getSessionExpiration().Unix(), 10)
return Session(session)
return session
}

return getSessionFromCookie(cookie)
}

func getSessionExpirationCookie(t time.Time) string {
return strconv.FormatInt(t.Unix(), 10)
}

0 comments on commit 501d82c

Please sign in to comment.