read_request must return header table

This commit is contained in:
Cloud Wu
2014-07-22 21:52:18 +08:00
parent 932b2943dc
commit d2ad63da81

View File

@@ -52,8 +52,6 @@ local function recvheader(readline, header)
return header return header
end end
header = header or {}
local name, value local name, value
repeat repeat
if line:byte(1) == 9 then -- tab, append last line if line:byte(1) == 9 then -- tab, append last line
@@ -117,18 +115,15 @@ local function readall(readline, readbytes)
if httpver < 1.0 or httpver > 1.1 then if httpver < 1.0 or httpver > 1.1 then
return 505 -- HTTP Version not supported return 505 -- HTTP Version not supported
end end
local header = recvheader(readline) local header = recvheader(readline, {})
local length, mode local length = header["content-length"]
if header then if length then
length = header["content-length"] length = tonumber(length)
if length then end
length = tonumber(length) local mode = header["transfer-encoding"]
end if mode then
mode = header["transfer-encoding"] if mode ~= "identity" or mode ~= "chunked" then
if mode then return 501 -- Not Implemented
if mode ~= "identity" or mode ~= "chunked" then
return 501 -- Not Implemented
end
end end
end end
@@ -157,7 +152,7 @@ function httpd.read_request(readfunc)
end end
function httpd.write_response(writefunc, statuscode, bodyfunc, header) function httpd.write_response(writefunc, statuscode, bodyfunc, header)
local statusline = string.format("HTTP/1.1 %03d %s\r\n", statuscode, http_status_msg[statuscode]) local statusline = string.format("HTTP/1.1 %03d %s\r\n", statuscode, http_status_msg[statuscode] or "")
writefunc(statusline) writefunc(statusline)
if header then if header then
for k,v in pairs(header) do for k,v in pairs(header) do