Skip to content

Commit edf1ca1

Browse files
committed
Release 2.13.
1 parent 75acdc3 commit edf1ca1

File tree

3 files changed

+22
-12
lines changed

3 files changed

+22
-12
lines changed

Changes.md

+8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
All notable changes to `lua-resty-session` will be documented in this file.
44

5+
## [2.13] - 2016-11-21
6+
### Changed
7+
- On start we do send cookie now also if the settings have changed
8+
and the cookie expiry time needs to be reduced.
9+
10+
### Fixed
11+
- Memcache storage adapter had a missing ngx.null.
12+
513
## [2.12] - 2016-11-21
614
### Added
715
- Implemented pluggable session identifier generators.

lib/resty/session.lua

+13-12
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ local defaults = {
133133
defaults.secret = var.session_secret or random(32, true) or random(32)
134134

135135
local session = {
136-
_VERSION = "2.12"
136+
_VERSION = "2.13"
137137
}
138138

139139
session.__index = session
@@ -241,26 +241,25 @@ function session.open(opts)
241241
addr,
242242
scheme
243243
}
244+
self.opened = true
244245
local cookie = var["cookie_" .. self.name]
245246
if cookie then
246247
local i, e, d, h = self.storage:open(cookie, self.cookie.lifetime)
247248
if i and e and e > time() and d and h then
248-
self.id = i
249-
self.expires = e
250-
local k = hmac(self.secret, self.id .. e)
249+
local k = hmac(self.secret, i .. e)
251250
d = self.cipher:decrypt(d, k, i, self.key)
252251
if d and hmac(k, concat{ i, e, d, self.key }) == h then
253-
self.data = self.serializer.deserialize(d)
252+
d = self.serializer.deserialize(d)
253+
self.id = i
254+
self.expires = e
255+
self.data = type(d) == "table" and d or {}
254256
self.present = true
257+
return self, true
255258
end
256259
end
257260
end
258-
if not self.present then
259-
regenerate(self)
260-
end
261-
if type(self.data) ~= "table" then self.data = {} end
262-
self.opened = true
263-
return self, self.present
261+
regenerate(self, true)
262+
return self, false
264263
end
265264

266265
function session.start(opts)
@@ -273,7 +272,9 @@ function session.start(opts)
273272
local ok, err = self.storage:start(self.id)
274273
if not ok then return nil, err end
275274
end
276-
if self.expires - time() < self.cookie.renew then
275+
local now = time()
276+
if self.expires - now < self.cookie.renew or
277+
self.expires > now + self.cookie.lifetime then
277278
local ok, err = save(self)
278279
if not ok then return nil, err end
279280
end

lib/resty/session/storage/memcache.lua

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ local tonumber = tonumber
44
local concat = table.concat
55
local floor = math.floor
66
local sleep = ngx.sleep
7+
local null = ngx.null
78
local now = ngx.now
89
local var = ngx.var
910

0 commit comments

Comments
 (0)