mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-25 12:43:09 +00:00
read_request must return header table
This commit is contained in:
@@ -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,20 +115,17 @@ 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
|
|
||||||
length = header["content-length"]
|
|
||||||
if length then
|
if length then
|
||||||
length = tonumber(length)
|
length = tonumber(length)
|
||||||
end
|
end
|
||||||
mode = header["transfer-encoding"]
|
local mode = header["transfer-encoding"]
|
||||||
if mode then
|
if mode then
|
||||||
if mode ~= "identity" or mode ~= "chunked" then
|
if mode ~= "identity" or mode ~= "chunked" then
|
||||||
return 501 -- Not Implemented
|
return 501 -- Not Implemented
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
local body
|
local body
|
||||||
if mode == "chunked" then
|
if mode == "chunked" then
|
||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user