Permalink
Browse files

Revert "Do not read IO till EOF when the size is given"

This reverts commit 1270672.
  • Loading branch information...
1 parent b590347 commit eb911515e804525287338ab9b54f3f75e71adabe @nahi committed Oct 10, 2012
Showing with 12 additions and 21 deletions.
  1. +12 −11 lib/httpclient/http.rb
  2. +0 −10 test/test_httpclient.rb
View
@@ -562,21 +562,12 @@ def reset_pos(io)
end
def dump_file(io, dev)
- return dump_file_length(io, @size, dev) if @size
buf = ''
while !io.read(@chunk_size, buf).nil?
dev << buf
end
end
- def dump_file_length(io, size, dev)
- buf = ''
- while size > 0 && !(read = io.read(size > @chunk_size ? @chunk_size : size, buf)).nil?
- dev << buf
- size -= read.bytesize
- end
- end
-
def dump_chunks(io, dev)
buf = ''
while !io.read(@chunk_size, buf).nil?
@@ -609,8 +600,18 @@ def add(part)
if Message.file?(part)
@as_stream = true
@body << part
- # use chunked upload
- @size = nil
+ if part.respond_to?(:lstat)
+ @size += part.lstat.size
+ elsif part.respond_to?(:size)
+ if sz = part.size
+ @size += sz
+ else
+ @size = nil
+ end
+ else
+ # use chunked upload
+ @size = nil
+ end
elsif @body[-1].is_a?(String)
@body[-1] += part.to_s
@size += part.to_s.bytesize if @size
View
@@ -794,16 +794,6 @@ def myio.size
assert_match(/\r\nTransfer-Encoding: chunked\r\n/m, str.string)
end
- def test_post_with_io_size_mismatch
- myio = StringIO.new("45")
- def myio.size
- 1
- end
- @client.debug_dev = str = StringIO.new
- res = @client.post(serverurl + 'servlet', myio)
- assert_match(/\r\n4\n/, str.string, 'should send "4" not "45"')
- end
-
def test_post_async
param = {'1'=>'2', '3'=>'4'}
conn = @client.post_async(serverurl + 'servlet', param)

0 comments on commit eb91151

Please sign in to comment.