aboutsummaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authorWaqas Hussain <waqas20@gmail.com>2010-11-06 03:46:19 +0500
committerWaqas Hussain <waqas20@gmail.com>2010-11-06 03:46:19 +0500
commitc5bcc70db662a51e4e704b034646bf194aed8b35 (patch)
treec2241abc0364fb60e83aa45fc1099ca24ce03668 /util
parent8e491a46d717e89c8ff8dfe8c51e467cfa11455a (diff)
downloadprosody-c5bcc70db662a51e4e704b034646bf194aed8b35.tar.gz
prosody-c5bcc70db662a51e4e704b034646bf194aed8b35.zip
util.httpstream: Added support for chunked transfer encoding.
Diffstat (limited to 'util')
-rw-r--r--util/httpstream.lua13
1 files changed, 12 insertions, 1 deletions
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