summaryrefslogtreecommitdiffstats
path: root/server.lua
diff options
context:
space:
mode:
authorKaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>2013-03-15 10:58:36 +0200
committerKaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>2013-03-15 10:58:36 +0200
commitc72a57b99c93a14cdf924771455a74aa358227c6 (patch)
tree25407e84c18cdddc05ec7b3d9ce0b0c3541ce6a9 /server.lua
parentfe648009635c8b744c51303020fd0b3b9cfe83c9 (diff)
downloadaconf-c72a57b99c93a14cdf924771455a74aa358227c6.tar.bz2
aconf-c72a57b99c93a14cdf924771455a74aa358227c6.tar.xz
improved handling of nested transactions
add nested transaction support to protocol allow deferring validation to parent transaction process each update request within a nested transaction
Diffstat (limited to 'server.lua')
-rw-r--r--server.lua24
1 files changed, 11 insertions, 13 deletions
diff --git a/server.lua b/server.lua
index cbbc82f..592e1e1 100644
--- a/server.lua
+++ b/server.lua
@@ -64,13 +64,14 @@ return function(env)
txn_id = tonumber(env.HTTP_X_ACF_TRANSACTION_ID)
end
- local txn
+ local parent_txn
if txn_id then
- txn = txns[txn_id]
- if not txn then
+ parent_txn = txns[txn_id]
+ if not parent_txn then
return wrap(400, nil, 'Invalid transaction ID')
end
- else txn = acf.transaction.start() end
+ end
+ local txn = acf.transaction.start(parent_txn, true)
local function fetch_user(name)
user = name and txn:search('/auth/users')[name]
@@ -150,7 +151,7 @@ return function(env)
elseif method == 'PUT' then parent[name] = data
else return 405 end
- if not txn_id then txn:commit() end
+ txn:commit()
return 205
end
@@ -159,21 +160,18 @@ return function(env)
return 301, {['Location']='/browser/'}
end
- if not ({DELETE=true, POST=true})[method] then
- return 405
- end
-
- if txn_id then
- if method == 'POST' then txn:commit() end
+ if ({DELETE=true, PUT=true})[method] then
+ if not txn_id then return 405 end
+ if method == 'PUT' then parent_txn:commit() end
txns[txn_id] = nil
return 204
end
- if method == 'DELETE' then return 405 end
+ if method ~= 'POST' then return 405 end
last_txn_id = last_txn_id + 1
local txn_id = last_txn_id
- txns[txn_id] = txn
+ txns[txn_id] = acf.transaction.start(parent_txn)
return 204, {['X-ACF-Transaction-ID']=txn_id}
end