From 1751ea76a4583a1796324135fa5d30fef6abfc24 Mon Sep 17 00:00:00 2001 From: ko1 Date: Tue, 3 Apr 2018 10:22:45 +0000 Subject: repatch r62966 and r62969. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63074 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/webrick/httprequest.rb | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'lib/webrick/httprequest.rb') diff --git a/lib/webrick/httprequest.rb b/lib/webrick/httprequest.rb index b40bcb0d57..c40f7c16e4 100644 --- a/lib/webrick/httprequest.rb +++ b/lib/webrick/httprequest.rb @@ -257,6 +257,32 @@ module WEBrick @body.empty? ? nil : @body end + ## + # Prepares the HTTPRequest object for use as the + # source for IO.copy_stream + + def body_reader + @body_tmp = [] + @body_rd = Fiber.new do + body do |buf| + @body_tmp << buf + Fiber.yield + end + end + @body_rd.resume # grab the first chunk and yield + self + end + + # for IO.copy_stream. Note: we may return a larger string than +size+ + # here; but IO.copy_stream does not care. + def readpartial(size, buf = ''.b) # :nodoc + res = @body_tmp.shift or raise EOFError, 'end of file reached' + buf.replace(res) + res.clear + @body_rd.resume # get more chunks + buf + end + ## # Request query as a Hash -- cgit v1.2.3