ruby-changes:63066
From: John <ko1@a...>
Date: Thu, 24 Sep 2020 21:42:22 +0900 (JST)
Subject: [ruby-changes:63066] 96da24f279 (master): [ruby/webrick] Make readpartial limit chunk to appropriate size
https://git.ruby-lang.org/ruby.git/commit/?id=96da24f279 From 96da24f279e10945be8e87fd63c54b63c331d119 Mon Sep 17 00:00:00 2001 From: John W Higgins <wishdev@g...> Date: Wed, 15 Jul 2020 08:20:31 -0700 Subject: [ruby/webrick] Make readpartial limit chunk to appropriate size https://github.com/ruby/webrick/commit/e693f501bd diff --git a/lib/webrick/httprequest.rb b/lib/webrick/httprequest.rb index 87dc879..c781797 100644 --- a/lib/webrick/httprequest.rb +++ b/lib/webrick/httprequest.rb @@ -9,6 +9,7 @@ https://github.com/ruby/ruby/blob/trunk/lib/webrick/httprequest.rb#L9 # # $IPR: httprequest.rb,v 1.64 2003/07/13 17:18:22 gotoyuzo Exp $ +require 'fiber' require 'uri' require_relative 'httpversion' require_relative 'httpstatus' @@ -273,13 +274,17 @@ module WEBrick https://github.com/ruby/ruby/blob/trunk/lib/webrick/httprequest.rb#L274 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 -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/