diff options
Diffstat (limited to 'net/http/parser.lua')
-rw-r--r-- | net/http/parser.lua | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/net/http/parser.lua b/net/http/parser.lua index 1e698728..4e4ae9fb 100644 --- a/net/http/parser.lua +++ b/net/http/parser.lua @@ -38,7 +38,7 @@ function httpstream.new(success_cb, error_cb, parser_type, options_cb) local have_body; local error; return { - feed = function(self, data) + feed = function(_, data) if error then return nil, "parse has failed"; end if not data then -- EOF if buftable then buf, buftable = t_concat(buf), false; end @@ -46,7 +46,7 @@ function httpstream.new(success_cb, error_cb, parser_type, options_cb) packet.body = buf; success_cb(packet); elseif buf ~= "" then -- unexpected EOF - error = true; return error_cb(); + error = true; return error_cb("unexpected-eof"); end return; end @@ -134,6 +134,9 @@ function httpstream.new(success_cb, error_cb, parser_type, options_cb) if state then -- read body if client then if chunked then + if chunk_start and buflen - chunk_start - 2 < chunk_size then + return; + end -- not enough data if buftable then buf, buftable = t_concat(buf), false; end if not buf:find("\r\n", nil, true) then return; @@ -150,6 +153,7 @@ function httpstream.new(success_cb, error_cb, parser_type, options_cb) elseif buflen - chunk_start - 2 >= chunk_size then -- we have a chunk packet.body = packet.body..buf:sub(chunk_start, chunk_start + (chunk_size-1)); buf = buf:sub(chunk_start + chunk_size + 2); + buflen = buflen - (chunk_start + chunk_size + 2 - 1); chunk_size, chunk_start = nil, nil; else -- Partial chunk remaining break; |