diff options
author | Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi> | 2014-02-24 18:52:31 +0200 |
---|---|---|
committer | Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi> | 2014-02-26 16:52:57 +0200 |
commit | ebd494e6c6fdcc7d4ca57084b81f3fd201b5e720 (patch) | |
tree | faca320713f4e25dac98eb6f64f5080d9647d500 | |
parent | 5029b72dbf17285a345deb5d57b6dcada7af9d79 (diff) | |
download | acf2-ebd494e6c6fdcc7d4ca57084b81f3fd201b5e720.tar.bz2 acf2-ebd494e6c6fdcc7d4ca57084b81f3fd201b5e720.tar.xz |
server: expire stale sessions
-rw-r--r-- | server.lua | 14 |
1 files changed, 11 insertions, 3 deletions
@@ -18,11 +18,14 @@ math.randomseed(os.time()) local save_req = os.execute('[ $(stat -f -c "%T" /) = tmpfs ]') -- TODO shared storage for sessions --- TODO expire stale sessions local sessions = {} return function(env) + for sid, session in pairs(sessions) do + if session.expires < os.time() then sessions[sid] = nil end + end + local method = env.REQUEST_METHOD local path = env.PATH_INFO @@ -67,11 +70,14 @@ return function(env) end end - local sid = tonumber(env.HTTP_X_ACF_AUTH_TOKEN) local session, user, txn_id + function reset_session_expiry() session.expires = os.time() + 600 end + + local sid = tonumber(env.HTTP_X_ACF_AUTH_TOKEN) if sid then session = sessions[sid] if not session then return wrap(401) end + reset_session_expiry() user = session.user txn_id = tonumber(env.HTTP_X_ACF_TRANSACTION_ID) end @@ -114,7 +120,9 @@ return function(env) sid = math.floor(math.random() * 2^32) until not sessions[sid] - sessions[sid] = {user=data.username, last_txn_id=0, txns={}} + session = {user=data.username, last_txn_id=0, txns={}} + reset_session_expiry() + sessions[sid] = session return wrap( 204, { |