aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWaqas Hussain <waqas20@gmail.com>2010-11-06 01:58:46 +0500
committerWaqas Hussain <waqas20@gmail.com>2010-11-06 01:58:46 +0500
commit1bc9eb48694eda80d23beeeb5e197120a21e6fa5 (patch)
treef70fdcb95cf460e5352f4f9c1bb77b817672fbcf
parent30c65df5d6c20faba29e476e9048e1db153571ff (diff)
downloadprosody-1bc9eb48694eda80d23beeeb5e197120a21e6fa5.tar.gz
prosody-1bc9eb48694eda80d23beeeb5e197120a21e6fa5.zip
util.httpstream: Don't attempt to read response body for HEAD requests, or when status code indicates no body is present.
-rw-r--r--util/httpstream.lua25
1 files changed, 16 insertions, 9 deletions
diff --git a/util/httpstream.lua b/util/httpstream.lua
index c96abe22..1aad0d91 100644
--- a/util/httpstream.lua
+++ b/util/httpstream.lua
@@ -71,16 +71,23 @@ local function parser(success_cb, parser_type, options_cb)
local headers = readheaders();
-- read body
+ local have_body = not
+ ( (options_cb and options_cb().method == "HEAD")
+ or (status_code == 204 or status_code == 304 or status_code == 301)
+ or (status_code >= 100 and status_code < 200) );
+
local body;
- local len = tonumber(headers["content-length"]);
- if len then -- TODO check for invalid len
- body = readlength(len);
- else -- read to end
- repeat
- local newdata = coroutine.yield();
- data = data..newdata;
- until newdata == "";
- body, data = data, "";
+ if have_body then
+ local len = tonumber(headers["content-length"]);
+ if len then -- TODO check for invalid len
+ body = readlength(len);
+ else -- read to end
+ repeat
+ local newdata = coroutine.yield();
+ data = data..newdata;
+ until newdata == "";
+ body, data = data, "";
+ end
end
success_cb({