Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http.request: possibility to defer body receiving if sink is not specified #438

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 25 additions & 5 deletions src/http.lua
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,16 @@ end
local code, status = h:receivestatusline()
-- if it is an HTTP/0.9 server, simply get the body and we are done
if not code then
h:receive09body(status, nreqt.sink, nreqt.step)
return 1, 200
if nreqt.sink then
h:receive09body(status, nreqt.sink, nreqt.step)
return 1, 200
else
return socket.protect(function(sink, step)
if sink then
return h:receive09body(status, sink, step or nreqt.step)
end
end), 200
end
elseif code == 408 then
return 1, code
end
Expand All @@ -387,11 +395,23 @@ end
return tredirect(reqt, headers.location)
end
-- here we are finally done
local receivebody
if shouldreceivebody(nreqt, code) then
h:receivebody(headers, nreqt.sink, nreqt.step)
if nreqt.sink then
h:receivebody(headers, nreqt.sink, nreqt.step)
else
receivebody = socket.protect(function(sink, step)
local res, err
if sink then
res, err = h:receivebody(headers, sink, step or nreqt.step)
end
h:close()
return res, err
end)
end
end
h:close()
return 1, code, headers, status
if not receivebody then h:close() end
return receivebody or 1, code, headers, status
end

-- turns an url and a body into a generic request
Expand Down
Loading