Skip to content
Merged
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
10 changes: 10 additions & 0 deletions session.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ var defaultOptions = options{
cookieLifeTime: 3600 * 24 * 7,
expired: 7200,
secure: true,
sameSite: http.SameSiteDefaultMode,
sessionID: func(_ context.Context) string {
return newUUID()
},
Expand All @@ -43,6 +44,7 @@ type options struct {
cookieLifeTime int
secure bool
domain string
sameSite http.SameSite
expired int64
sessionID IDHandlerFunc
enableSetCookie bool
Expand Down Expand Up @@ -90,6 +92,13 @@ func SetSecure(secure bool) Option {
}
}

// SetSameSite Set SameSite attribute of the cookie
func SetSameSite(sameSite http.SameSite) Option {
return func(o *options) {
o.sameSite = sameSite
}
}

// SetExpired Set session expiration time (in seconds)
func SetExpired(expired int64) Option {
return func(o *options) {
Expand Down Expand Up @@ -261,6 +270,7 @@ func (m *Manager) setCookie(sessionID string, w http.ResponseWriter, r *http.Req
HttpOnly: true,
Secure: m.isSecure(r),
Domain: m.opts.domain,
SameSite: m.opts.sameSite,
}

if v := m.opts.cookieLifeTime; v > 0 {
Expand Down