예제 #1
0
func (ss signedCookieSessionHandler) writeToResponse(s SignedCookieSession, resp goanna.Response) {
	bytes, err := s.sessionData.Unmarshal()
	if err != nil {
		log.Println(err.Error())
	}

	cookie := http.Cookie{
		Name:     ss.CookieName,
		Value:    base64.URLEncoding.EncodeToString(bytes),
		HttpOnly: true,
		Secure:   ss.Secure,
		Path:     "/",
	}
	ss.CookieSigner.EncodeCookie(&cookie)

	maxage := int(s.MaxAge() / time.Second)
	if maxage != 0 {
		if s.preferExpires {
			cookie.Expires = time.Now().Add(s.MaxAge())
		} else {
			cookie.MaxAge = maxage
		}
	}
	resp.SetCookie(cookie)
}
예제 #2
0
func (s SignedCookieSession) WriteToResponse(resp goanna.Response) {
	bytes := marshalSessionData(*s.data)

	cookie := http.Cookie{
		Name:     s.name,
		Value:    s.CookieSigner.EncodeRawData(bytes),
		Expires:  s.Expiry(),
		HttpOnly: true,
	}
	resp.SetCookie(cookie)
}