X-Git-Url: https://git.enpas.org/?a=blobdiff_plain;f=util%2Fhttpstream.lua;h=4b5060a1a6835e1303a463af5d2a9d0d8474c636;hb=0ef23c673d1d620c9c1cc3e8aed43add63634426;hp=b567712811b56f0ffe9a254856f916a7d1998668;hpb=7350b4c8be670bb26ac505df040cc3266c6c74b8;p=prosody.git diff --git a/util/httpstream.lua b/util/httpstream.lua index b5677128..4b5060a1 100644 --- a/util/httpstream.lua +++ b/util/httpstream.lua @@ -80,7 +80,18 @@ local function parser(success_cb, parser_type, options_cb) local body; if have_body then local len = tonumber(headers["content-length"]); - if len then -- TODO check for invalid len + if headers["transfer-encoding"] == "chunked" then + body = ""; + while true do + local chunk_size = readline():match("^%x+"); + if not chunk_size then coroutine.yield("invalid-chunk-size"); end + chunk_size = tonumber(chunk_size, 16) + if chunk_size == 0 then break; end + body = body..readlength(chunk_size); + if readline() ~= "" then coroutine.yield("invalid-chunk-ending"); end + end + local trailers = readheaders(); + elseif len then -- TODO check for invalid len body = readlength(len); else -- read to end repeat