@@ -6,6 +6,7 @@ local hmac = ngx.hmac_sha1
6
6
local time = ngx .time
7
7
local http_time = ngx .http_time
8
8
local find = string.find
9
+ local sub = string.sub
9
10
local type = type
10
11
local pcall = pcall
11
12
local tonumber = tonumber
@@ -96,6 +97,21 @@ local function setcookie(session, value, expires)
96
97
return true
97
98
end
98
99
100
+ local function getcookie (name , i )
101
+ local n = { " cookie_" , name }
102
+ if i then
103
+ n [3 ] = " ."
104
+ n [4 ] = i
105
+ else
106
+ i = 1
107
+ end
108
+ local c = var [concat (n )]
109
+ if not c then return nil end
110
+ local l = # c
111
+ if l < 4001 then return c end
112
+ return concat { sub (c , 1 , 4000 ), getcookie (name , i + 1 ) }
113
+ end
114
+
99
115
local function save (session , close )
100
116
session .expires = time () + session .cookie .lifetime
101
117
local i , e , s = session .id , session .expires , session .storage
@@ -147,7 +163,7 @@ local defaults = {
147
163
defaults .secret = var .session_secret or random (32 , true ) or random (32 )
148
164
149
165
local session = {
150
- _VERSION = " 2.14 "
166
+ _VERSION = " 2.15-dev "
151
167
}
152
168
153
169
session .__index = session
@@ -245,7 +261,7 @@ function session.open(opts)
245
261
scheme
246
262
}
247
263
self .opened = true
248
- local cookie = var [ " cookie_ " .. self .name ]
264
+ local cookie = getcookie ( self .name )
249
265
if cookie then
250
266
local i , e , d , h = self .storage :open (cookie , self .cookie .lifetime )
251
267
if i and e and e > time () and d and h then
0 commit comments