From b18962929b6f54d342c84e0ea9be38c29b60a513 Mon Sep 17 00:00:00 2001 From: Cloud Wu Date: Mon, 4 Aug 2014 18:08:05 +0800 Subject: [PATCH] bugfix: chunked mode --- lualib/http/httpd.lua | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lualib/http/httpd.lua b/lualib/http/httpd.lua index 190b6b93..a0c027f2 100644 --- a/lualib/http/httpd.lua +++ b/lualib/http/httpd.lua @@ -46,6 +46,11 @@ local http_status_msg = { } local function recvheader(readbytes, limit, lines, header) + if #header >= 2 then + if header:find "^\r\n" then + return header:sub(3) + end + end local result local e = header:find("\r\n\r\n", 1, true) if e then @@ -62,6 +67,9 @@ local function recvheader(readbytes, limit, lines, header) result = header:sub(e+4) break end + if header:find "^\r\n" then + return header:sub(3) + end end end for v in header:gmatch("(.-)\r\n") do @@ -156,10 +164,6 @@ local function recvchunkedbody(readbytes, bodylimit, header, body) end end - body = readcrln(readbytes, body) - if not body then - return - end local tmpline = {} body = recvheader(readbytes, 8192, tmpline, body) if not body then @@ -194,7 +198,7 @@ local function readall(readbytes, bodylimit) end local mode = header["transfer-encoding"] if mode then - if mode ~= "identity" or mode ~= "chunked" then + if mode ~= "identity" and mode ~= "chunked" then return 501 -- Not Implemented end end