Comparison

util/httpstream.lua @ 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
parent 3568:51d5578965a5
child 3902:a34333fcae72
comparison
equal deleted inserted replaced
3569:f30da46e0add 3570:6ef68af9431c
78 or (status_code >= 100 and status_code < 200) ); 78 or (status_code >= 100 and status_code < 200) );
79 79
80 local body; 80 local body;
81 if have_body then 81 if have_body then
82 local len = tonumber(headers["content-length"]); 82 local len = tonumber(headers["content-length"]);
83 if len then -- TODO check for invalid len 83 if headers["transfer-encoding"] == "chunked" then
84 body = "";
85 while true do
86 local chunk_size = readline():match("^%x+");
87 if not chunk_size then coroutine.yield("invalid-chunk-size"); end
88 chunk_size = tonumber(chunk_size, 16)
89 if chunk_size == 0 then break; end
90 body = body..readlength(chunk_size);
91 if readline() ~= "" then coroutine.yield("invalid-chunk-ending"); end
92 end
93 local trailers = readheaders();
94 elseif len then -- TODO check for invalid len
84 body = readlength(len); 95 body = readlength(len);
85 else -- read to end 96 else -- read to end
86 repeat 97 repeat
87 local newdata = coroutine.yield(); 98 local newdata = coroutine.yield();
88 data = data..newdata; 99 data = data..newdata;