Skip to content

Commit

Permalink
simplify readbody
Browse files Browse the repository at this point in the history
  • Loading branch information
IanButterworth committed Nov 16, 2021
1 parent c0ac2f3 commit 37b2f31
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions src/StreamRequest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -139,22 +139,22 @@ end
writechunk(http, req, body::IO) = writebodystream(http, req, body)
writechunk(http, req, body) = write(http, body)

function readbody(http::Stream, res::Response, response_stream, reached_redirect_limit)
if response_stream === nothing
res.body = read(http)
else
if reached_redirect_limit || !isredirect(res)
res.body = body_was_streamed
if Streams.ntoread(http) == unknown_length
write(response_stream, http)
else
while http.ntoread > 0
readbytes!(http, response_stream, http.ntoread)
end
end
close(response_stream)
function readbody(http::Stream, res::Response, ::Nothing, ::Bool)
res.body = read(http)
return
end

function readbody(http::Stream, res::Response, response_stream, reached_redirect_limit::Bool)
if reached_redirect_limit || !isredirect(res)
res.body = body_was_streamed
if http.ntoread == unknown_length
write(response_stream, http)
else
readbytes!(http, response_stream, http.ntoread)
end
close(response_stream)
end
return
end

end # module StreamRequest

0 comments on commit 37b2f31

Please sign in to comment.