Project

General

Profile

Feature #5605 ยป 0001-net-http-use-IO.copy_stream-for-requests-using-body_.patch

normalperson (Eric Wong), 11/10/2011 09:55 AM

View differences:

lib/net/http.rb
private
class Chunker
def initialize(sock)
@sock = sock
@prev = nil
end
def write(buf)
# avoid memcpy() of buf, buf can huge and eat memory bandwidth
@sock.write("#{buf.bytesize.to_s(16)}\r\n")
rv = @sock.write(buf)
@sock.write("\r\n")
rv
end
def finish
@sock.write("0\r\n\r\n")
end
end
def send_request_with_body(sock, ver, path, body)
self.content_length = body.bytesize
delete 'Transfer-Encoding'
......
write_header sock, ver, path
wait_for_continue sock, ver if sock.continue_timeout
if chunked?
while s = f.read(1024)
sock.write(sprintf("%x\r\n", s.length) << s << "\r\n")
end
sock.write "0\r\n\r\n"
chunker = Chunker.new(sock)
IO.copy_stream(f, chunker)
chunker.finish
else
while s = f.read(1024)
sock.write s
end
# copy_stream can sendfile() to sock.io unless we use SSL.
# If sock.io is an SSLSocket, copy_stream will hit SSL_write()
IO.copy_stream(f, sock.io)
end
end
    (1-1/1)