Skip to content

Commit

Permalink
Changed existing to present (it is a more clear one), see:
Browse files Browse the repository at this point in the history
  • Loading branch information
bungle committed Aug 4, 2015
1 parent c35ec80 commit 0d1b99b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
18 changes: 9 additions & 9 deletions lib/resty/session.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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"]
Expand Down Expand Up @@ -259,28 +259,28 @@ 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
else
self:regenerate()
end
self.started = true
return self, existing
return self, present
end

function session:regenerate(flush)
Expand All @@ -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
Expand Down

0 comments on commit 0d1b99b

Please sign in to comment.