Software /
code /
prosody
Changeset
3570:6ef68af9431c
util.httpstream: Added support for chunked transfer encoding.
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Sat, 06 Nov 2010 03:46:19 +0500 |
parents | 3569:f30da46e0add |
children | 3571:675d65036f31 |
files | util/httpstream.lua |
diffstat | 1 files changed, 12 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/util/httpstream.lua Sat Nov 06 03:46:00 2010 +0500 +++ b/util/httpstream.lua Sat Nov 06 03:46:19 2010 +0500 @@ -80,7 +80,18 @@ 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