@@ -5,9 +5,12 @@ local concat = table.concat
5
5
local hmac = ngx .hmac_sha1
6
6
local time = ngx .time
7
7
local http_time = ngx .http_time
8
+ local set_header = ngx .req .set_header
9
+ local clear_header = ngx .req .clear_header
8
10
local ceil = math.ceil
9
11
local max = math.max
10
12
local find = string.find
13
+ local gsub = string.gsub
11
14
local sub = string.sub
12
15
local type = type
13
16
local pcall = pcall
@@ -200,7 +203,7 @@ local function init()
200
203
end
201
204
202
205
local session = {
203
- _VERSION = " 2.16 "
206
+ _VERSION = " 2.17 "
204
207
}
205
208
206
209
session .__index = session
@@ -369,4 +372,51 @@ function session:destroy()
369
372
return setcookie (self , " " , true )
370
373
end
371
374
375
+ function session :hide ()
376
+ local cookies = var .http_cookie
377
+ if not cookies then
378
+ return
379
+ end
380
+ local r = {}
381
+ local n = self .name
382
+ local i = 1
383
+ local j = 0
384
+ local s = find (cookies , " ;" , 1 , true )
385
+ while s do
386
+ local c = sub (cookies , i , s - 1 )
387
+ local b = find (c , " =" , 1 , true )
388
+ if b then
389
+ local key = gsub (sub (c , 1 , b - 1 ), " ^%s+" , " " )
390
+ if key ~= n and key ~= " " then
391
+ local z = # n
392
+ if sub (key , z + 1 , z + 1 ) ~= " _" or not tonumber (sub (key , z + 2 )) then
393
+ j = j + 1
394
+ r [j ] = c
395
+ end
396
+ end
397
+ end
398
+ i = s + 1
399
+ s = find (cookies , " ;" , i , true )
400
+ end
401
+ local c = sub (cookies , i )
402
+ if c and c ~= " " then
403
+ local b = find (c , " =" , 1 , true )
404
+ if b then
405
+ local key = gsub (sub (c , 1 , b - 1 ), " ^%s+" , " " )
406
+ if key ~= n and key ~= " " then
407
+ local z = # n
408
+ if sub (key , z + 1 , z + 1 ) ~= " _" or not tonumber (sub (key , z + 2 )) then
409
+ j = j + 1
410
+ r [j ] = c
411
+ end
412
+ end
413
+ end
414
+ end
415
+ if j == 0 then
416
+ clear_header (" Cookie" )
417
+ else
418
+ set_header (" Cookie" , concat (r , " ; " , 1 , j ))
419
+ end
420
+ end
421
+
372
422
return session
0 commit comments