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

Make readpartial limit chunk to appropriate size #45

Merged
merged 2 commits into from
Jul 15, 2020
Merged
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
11 changes: 8 additions & 3 deletions lib/webrick/httprequest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#
# $IPR: httprequest.rb,v 1.64 2003/07/13 17:18:22 gotoyuzo Exp $

require 'fiber'
require 'uri'
require_relative 'httpversion'
require_relative 'httpstatus'
Expand Down Expand Up @@ -273,13 +274,17 @@ def body_reader
self
end

# for IO.copy_stream. Note: we may return a larger string than +size+
# here; but IO.copy_stream does not care.
# for IO.copy_stream.
def readpartial(size, buf = ''.b) # :nodoc
res = @body_tmp.shift or raise EOFError, 'end of file reached'
if res.length > size
@body_tmp.unshift(res[size..-1])
res = res[0..size - 1]
end
buf.replace(res)
res.clear
@body_rd.resume # get more chunks
# get more chunks - check alive? because we can take a partial chunk
@body_rd.resume if @body_rd.alive?
buf
end

Expand Down