Skip to content

Commit

Permalink
fix that retains streaming
Browse files Browse the repository at this point in the history
  • Loading branch information
IanButterworth committed Nov 16, 2021
1 parent 080e76b commit c0ac2f3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/StreamRequest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,13 @@ function readbody(http::Stream, res::Response, response_stream, reached_redirect
else
if reached_redirect_limit || !isredirect(res)
res.body = body_was_streamed
write(response_stream, read(http)) # use read(http) to ensure ntoread is respected
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)
end
end
Expand Down
2 changes: 2 additions & 0 deletions src/Streams.jl
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,8 @@ function Base.unsafe_read(http::Stream, p::Ptr{UInt8}, n::UInt)
nothing
end

Base.readbytes!(http::Stream, buf::Base.BufferStream, n=bytesavailable(http)) = Base.readbytes!(http, buf.buffer, n)

function Base.readbytes!(http::Stream, buf::IOBuffer, n=bytesavailable(http))
Base.ensureroom(buf, n)
unsafe_read(http, pointer(buf.data, buf.size + 1), n)
Expand Down

0 comments on commit c0ac2f3

Please sign in to comment.