summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authornormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-05-22 07:36:00 +0000
committernormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-05-22 07:36:00 +0000
commitcbedbaf9d9c7452afac2dfc0f06e1f72e235adea (patch)
tree89801eb158058dcaef552f48779355bfc1d3865d /lib
parent5565fed887e8a1a4d389f59a5de1000fec99ca2e (diff)
lib/net/protocol.rb: account read_bytes before caller sees it
Users may modify the chunk yielded to them in Net::HTTPResponse#read_body. This will allow users to reduce memory usage by calling String#clear on the buffer once they're done using it. * lib/net/protocol.rb (read): increment read_bytes earlier (read_all): ditto * test/net/http/test_httpresponse.rb (test_read_body_block_mod): new test git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r--lib/net/protocol.rb9
1 files changed, 6 insertions, 3 deletions
diff --git a/lib/net/protocol.rb b/lib/net/protocol.rb
index 797966ac7d..0e887d5aa9 100644
--- a/lib/net/protocol.rb
+++ b/lib/net/protocol.rb
@@ -119,12 +119,14 @@ module Net # :nodoc:
read_bytes = 0
begin
while read_bytes + @rbuf.size < len
- dest << (s = rbuf_consume(@rbuf.size))
+ s = rbuf_consume(@rbuf.size)
read_bytes += s.size
+ dest << s
rbuf_fill
end
- dest << (s = rbuf_consume(len - read_bytes))
+ s = rbuf_consume(len - read_bytes)
read_bytes += s.size
+ dest << s
rescue EOFError
raise unless ignore_eof
end
@@ -137,8 +139,9 @@ module Net # :nodoc:
read_bytes = 0
begin
while true
- dest << (s = rbuf_consume(@rbuf.size))
+ s = rbuf_consume(@rbuf.size)
read_bytes += s.size
+ dest << s
rbuf_fill
end
rescue EOFError