mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
[ruby/webrick] Make readpartial limit chunk to appropriate size
e693f501bd
This commit is contained in:
parent
46ba416a1f
commit
96da24f279
1 changed files with 8 additions and 3 deletions
|
@ -9,6 +9,7 @@
|
||||||
#
|
#
|
||||||
# $IPR: httprequest.rb,v 1.64 2003/07/13 17:18:22 gotoyuzo Exp $
|
# $IPR: httprequest.rb,v 1.64 2003/07/13 17:18:22 gotoyuzo Exp $
|
||||||
|
|
||||||
|
require 'fiber'
|
||||||
require 'uri'
|
require 'uri'
|
||||||
require_relative 'httpversion'
|
require_relative 'httpversion'
|
||||||
require_relative 'httpstatus'
|
require_relative 'httpstatus'
|
||||||
|
@ -273,13 +274,17 @@ module WEBrick
|
||||||
self
|
self
|
||||||
end
|
end
|
||||||
|
|
||||||
# for IO.copy_stream. Note: we may return a larger string than +size+
|
# for IO.copy_stream.
|
||||||
# here; but IO.copy_stream does not care.
|
|
||||||
def readpartial(size, buf = ''.b) # :nodoc
|
def readpartial(size, buf = ''.b) # :nodoc
|
||||||
res = @body_tmp.shift or raise EOFError, 'end of file reached'
|
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)
|
buf.replace(res)
|
||||||
res.clear
|
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
|
buf
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue