7
"xelbot.com/reprogl/container"
10
type ResponseWriter struct {
16
func (sw *ResponseWriter) SetSessionData(d *Store) {
20
func (sw *ResponseWriter) Write(b []byte) (int, error) {
23
return sw.ResponseWriter.Write(b)
26
func (sw *ResponseWriter) WriteHeader(code int) {
29
sw.ResponseWriter.WriteHeader(code)
32
func (sw *ResponseWriter) CheckAndWrite() {
34
var secureCookie *SecureCookie
35
switch sw.sessionData.status {
37
expiry := time.Now().Add(maxAge)
39
secureCookie = NewSecureCookie(
40
container.GetConfig().SessionHashKey,
41
container.GetConfig().SessionBlockKey,
44
sw.sessionData.mu.Lock()
45
sw.sessionData.data.deadline = deadline(expiry)
46
err := secureCookie.encode(sw.sessionData.data)
47
sw.sessionData.mu.Unlock()
53
writeCookie(sw, secureCookie, expiry)
55
secureCookie = NewSecureCookie(
56
container.GetConfig().SessionHashKey,
57
container.GetConfig().SessionBlockKey,
59
writeCookie(sw, secureCookie, time.Time{})
62
if len(sw.Header().Values("Set-Cookie")) > 0 {
63
sw.Header().Set("Cache-Control", `no-cache="Set-Cookie"`)
70
func writeCookie(w http.ResponseWriter, c CookieInterface, expiry time.Time) {
71
cookie := &http.Cookie{
77
SameSite: http.SameSiteDefaultMode,
81
cookie.Expires = time.Unix(1, 0)
83
} else if c.Persist() {
84
cookie.Expires = time.Unix(expiry.Unix()+1, 0)
85
cookie.MaxAge = int(time.Until(expiry).Seconds() + 1)
88
http.SetCookie(w, cookie)