From 0d1b99be2bbb63c170554fb5c90f30b0da139f0d Mon Sep 17 00:00:00 2001 From: Aapo Talvensaari Date: Tue, 4 Aug 2015 16:49:09 +0300 Subject: [PATCH] Changed existing to present (it is a more clear one), see: https://github.com/bungle/lua-resty-session/issues/12 --- README.md | 8 ++++---- lib/resty/session.lua | 18 +++++++++--------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index c388369e..aef144cf 100644 --- a/README.md +++ b/README.md @@ -177,7 +177,7 @@ local session = require("resty.session").open() -- Set some options (overwriting the defaults or nginx configuration variables) local session = require("resty.session").open{ identifier = { length = 32 }} -- Read some data -if session.existing then +if session.present then ngx.print(session.data.uid) end -- Now let's really start the session @@ -260,9 +260,9 @@ session:destroy() `session.id` holds the current session id. By default it is 16 bytes long (raw binary bytes). It is automatically generated. -#### boolean session.existing +#### boolean session.present -`session.existing` can be used to check if the session that was opened with `session.open` or `session.start` +`session.present` can be used to check if the session that was opened with `session.open` or `session.start` was really a one the was received from a client. If the session is a new one, this will be false. #### boolean session.opened @@ -279,7 +279,7 @@ object. #### boolean session.destroyed `session.destroyed` can be used to check if the `session:destroy()` was called for the current session -object. It will also set `session.opened`, `session.started`, and `session.existing` to false. +object. It will also set `session.opened`, `session.started`, and `session.present` to false. #### number session.identifier.length diff --git a/lib/resty/session.lua b/lib/resty/session.lua index d891d655..fb529409 100644 --- a/lib/resty/session.lua +++ b/lib/resty/session.lua @@ -178,7 +178,7 @@ function session.new(opts) name = y.name or z.name, data = y.data or {}, secret = y.secret or z.secret, - existing = false, + present = false, opened = false, started = false, destroyed = false, @@ -208,7 +208,7 @@ end function session.open(opts) if getmetatable(opts) == session and opts.opened then - return opts, opts.existing + return opts, opts.present end local self = session.new(opts) local scheme = ngx_header["X-Forwarded-Proto"] @@ -259,20 +259,20 @@ function session.open(opts) d = a:decrypt(d) if d and hmac(k, concat{ self.id, self.expires, d, self.key }) == h then self.data = json.decode(d) - self.existing = true + self.present = true end end if type(self.data) ~= "table" then self.data = {} end self.opened = true - return self, self.existing + return self, self.present end function session.start(opts) if getmetatable(opts) == session and opts.started then - return opts, opts.existing + return opts, opts.present end - local self, existing = session.open(opts) - if existing then + local self, present = session.open(opts) + if present then if self.expires - time() < self.cookie.renew then self:save() end @@ -280,7 +280,7 @@ function session.start(opts) self:regenerate() end self.started = true - return self, existing + return self, present end function session:regenerate(flush) @@ -300,7 +300,7 @@ end function session:destroy() self.data = {} - self.existing = false + self.present = false self.opened = false self.started = false self.destroyed = true