diff options
-rw-r--r-- | server.lua | 25 |
1 files changed, 12 insertions, 13 deletions
@@ -22,18 +22,17 @@ return function(env) local method = env.REQUEST_METHOD local path = env.REQUEST_URI - local function wrap(code, headers, res) + local function wrap(code, headers, res, encode) if not headers then headers = {} end - local ctype - if type(res) == 'table' then - ctype = 'application/json' - res = json.encode(res) - else - ctype = 'text/plain' - if not res then res = '' end - end - headers['Content-Type'] = ctype + if res then + local ctype + if encode then + ctype = 'application/json' + res = json.encode(res) + else ctype = 'text/plain' end + headers['Content-Type'] = ctype + else res = '' end return code, headers, coroutine.wrap( function() coroutine.yield(res) end @@ -225,9 +224,9 @@ return function(env) end ) - if success then return wrap(code, hdr, res) end + if success then return wrap(code, hdr, res, true) end - if code.conflict then return wrap(409, nil, code.conflict) end + if code.conflict then return wrap(409, nil, code.conflict, true) end - return wrap(422, nil, code) + return wrap(422, nil, code, true) end |