Skip to content

Commit

Permalink
Make SetExpiry always update cookie on Save
Browse files Browse the repository at this point in the history
  • Loading branch information
hi019 committed Jun 22, 2021
1 parent b72297e commit 3d821f4
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions middleware/session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ import (
)

type Session struct {
id string // session id
fresh bool // if new session
ctx *fiber.Ctx // fiber context
config *Store // store configuration
data *data // key value data
byteBuffer *bytes.Buffer // byte buffer for the en- and decode
exp time.Duration // expiration of this session
id string // session id
fresh bool // if new session
ctx *fiber.Ctx // fiber context
config *Store // store configuration
data *data // key value data
byteBuffer *bytes.Buffer // byte buffer for the en- and decode
exp time.Duration // expiration of this session
shouldSetSession bool
}

var sessionPool = sync.Pool{
Expand Down Expand Up @@ -138,7 +139,7 @@ func (s *Session) Save() error {
}

// Create session with the session ID if fresh
if s.fresh {
if s.fresh || s.shouldSetSession {
s.setSession()
}

Expand Down Expand Up @@ -174,6 +175,7 @@ func (s *Session) Keys() []string {
// SetExpiry sets a specific expiration for this session
func (s *Session) SetExpiry(exp time.Duration) {
s.exp = exp
s.shouldSetSession = true
}

func (s *Session) setSession() {
Expand Down

0 comments on commit 3d821f4

Please sign in to comment.