# HG changeset patch # User Waqas Hussain <waqas20@gmail.com> # Date 1288990726 -18000 # Node ID 94828fb2dab8aa43d66dcfcb2dce7e89cda5a4de # Parent 75d287daad16cdd092d632428102c7bd5bfb058f util.httpstream: Don't attempt to read response body for HEAD requests, or when status code indicates no body is present. diff -r 75d287daad16 -r 94828fb2dab8 util/httpstream.lua --- a/util/httpstream.lua Sat Nov 06 01:54:58 2010 +0500 +++ b/util/httpstream.lua Sat Nov 06 01:58:46 2010 +0500 @@ -71,16 +71,23 @@ 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({