Software /
code /
prosody
Comparison
util/httpstream.lua @ 3567:94828fb2dab8
util.httpstream: Don't attempt to read response body for HEAD requests, or when status code indicates no body is present.
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Sat, 06 Nov 2010 01:58:46 +0500 |
parent | 3566:75d287daad16 |
child | 3568:51d5578965a5 |
comparison
equal
deleted
inserted
replaced
3566:75d287daad16 | 3567:94828fb2dab8 |
---|---|
69 local httpversion, status_code, reason_phrase = status_line:match("^HTTP/(%S+)%s+(%d%d%d)%s+(.*)$"); | 69 local httpversion, status_code, reason_phrase = status_line:match("^HTTP/(%S+)%s+(%d%d%d)%s+(.*)$"); |
70 if not httpversion then coroutine.yield("invalid-status-line"); end | 70 if not httpversion then coroutine.yield("invalid-status-line"); end |
71 local headers = readheaders(); | 71 local headers = readheaders(); |
72 | 72 |
73 -- read body | 73 -- read body |
74 local have_body = not | |
75 ( (options_cb and options_cb().method == "HEAD") | |
76 or (status_code == 204 or status_code == 304 or status_code == 301) | |
77 or (status_code >= 100 and status_code < 200) ); | |
78 | |
74 local body; | 79 local body; |
75 local len = tonumber(headers["content-length"]); | 80 if have_body then |
76 if len then -- TODO check for invalid len | 81 local len = tonumber(headers["content-length"]); |
77 body = readlength(len); | 82 if len then -- TODO check for invalid len |
78 else -- read to end | 83 body = readlength(len); |
79 repeat | 84 else -- read to end |
80 local newdata = coroutine.yield(); | 85 repeat |
81 data = data..newdata; | 86 local newdata = coroutine.yield(); |
82 until newdata == ""; | 87 data = data..newdata; |
83 body, data = data, ""; | 88 until newdata == ""; |
89 body, data = data, ""; | |
90 end | |
84 end | 91 end |
85 | 92 |
86 success_cb({ | 93 success_cb({ |
87 code = status_code; | 94 code = status_code; |
88 responseversion = httpversion; | 95 responseversion = httpversion; |