summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEmil Renner Berthing <esmil@mailme.dk>2013-01-06 16:16:22 +0100
committerEmil Renner Berthing <esmil@mailme.dk>2013-01-06 20:46:38 +0100
commit314aeedc740be792145c732980a225290252db6b (patch)
treeda7192e770bc649a705e798ed23fe161fe0817d0
parentbb9d813fb67ac9290544ef6d3c3f82e19fe84029 (diff)
downloadlem-314aeedc740be792145c732980a225290252db6b.tar.gz
lem-314aeedc740be792145c732980a225290252db6b.tar.xz
lem-314aeedc740be792145c732980a225290252db6b.zip
http/server: small fixes
-rw-r--r--lem/http/server.lua23
1 files changed, 17 insertions, 6 deletions
diff --git a/lem/http/server.lua b/lem/http/server.lua
index 932b4df..69bdbb9 100644
--- a/lem/http/server.lua
+++ b/lem/http/server.lua
@@ -140,7 +140,6 @@ do
local n = 0
return setmetatable({
headers = {},
- status = 200,
version = req.version,
add = function(self, ...)
n = n + 1
@@ -198,9 +197,15 @@ do
end
end
- if res.status == 200 and #res == 0 and res.file == nil then
- res.status = 204
- elseif headers['Content-Length'] == nil then
+ if not res.status then
+ if #res == 0 and file == nil then
+ res.status = 204
+ else
+ res.status = 200
+ end
+ end
+
+ if headers['Content-Length'] == nil and res.status ~= 204 then
local len
if file then
len = file:size()
@@ -222,6 +227,10 @@ do
headers['Server'] = 'Hathaway/0.1 LEM/0.3'
end
+ if req.headers['Connection'] == 'close' and headers['Connection'] == nil then
+ headers['Connection'] = 'close'
+ end
+
local robe, i = {}, 1
do
local status = res.status
@@ -251,7 +260,10 @@ do
ok, err = client:sendfile(file, headers['Content-Length'])
if close then file:close() end
else
- ok, err = client:write(concat(res))
+ local body = concat(res)
+ if #body > 0 then
+ ok, err = client:write(body)
+ end
end
if not ok then self.debug('write', err) break end
end
@@ -260,7 +272,6 @@ do
if not ok then self.debug('uncork', err) break end
until version == '1.0'
- or req.headers['Connection'] == 'close'
or headers['Connection'] == 'close'
client:close()