Skip to content

Commit e693f50

Browse files
authored
Make readpartial limit chunk to appropriate size
1 parent dc453e5 commit e693f50

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

lib/webrick/httprequest.rb

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#
1010
# $IPR: httprequest.rb,v 1.64 2003/07/13 17:18:22 gotoyuzo Exp $
1111

12+
require 'fiber'
1213
require 'uri'
1314
require_relative 'httpversion'
1415
require_relative 'httpstatus'
@@ -273,13 +274,17 @@ def body_reader
273274
self
274275
end
275276

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

0 commit comments

Comments
 (0)