* lib/net/http.rb (Net::HTTP#send_request_with_body_stream):
use IO.copy_stream for requests using body_stream. patched by Eric Wong. [ruby-core:40898] [Feature #5605] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35281 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
6a1f418672
commit
b386b25aac
@ -1,3 +1,9 @@
|
|||||||
|
Tue Apr 10 18:19:32 2012 NARUSE, Yui <naruse@ruby-lang.org>
|
||||||
|
|
||||||
|
* lib/net/http.rb (Net::HTTP#send_request_with_body_stream):
|
||||||
|
use IO.copy_stream for requests using body_stream.
|
||||||
|
patched by Eric Wong. [ruby-core:40898] [Feature #5605]
|
||||||
|
|
||||||
Tue Apr 10 16:53:21 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Tue Apr 10 16:53:21 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* thread_pthread.c: add prototype declarations for older Mac OS X.
|
* thread_pthread.c: add prototype declarations for older Mac OS X.
|
||||||
|
@ -1987,6 +1987,25 @@ module Net #:nodoc:
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
class Chunker #:nodoc:
|
||||||
|
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)
|
def send_request_with_body(sock, ver, path, body)
|
||||||
self.content_length = body.bytesize
|
self.content_length = body.bytesize
|
||||||
delete 'Transfer-Encoding'
|
delete 'Transfer-Encoding'
|
||||||
@ -2005,14 +2024,13 @@ module Net #:nodoc:
|
|||||||
write_header sock, ver, path
|
write_header sock, ver, path
|
||||||
wait_for_continue sock, ver if sock.continue_timeout
|
wait_for_continue sock, ver if sock.continue_timeout
|
||||||
if chunked?
|
if chunked?
|
||||||
while s = f.read(1024)
|
chunker = Chunker.new(sock)
|
||||||
sock.write(sprintf("%x\r\n", s.length) << s << "\r\n")
|
IO.copy_stream(f, chunker)
|
||||||
end
|
chunker.finish
|
||||||
sock.write "0\r\n\r\n"
|
|
||||||
else
|
else
|
||||||
while s = f.read(1024)
|
# copy_stream can sendfile() to sock.io unless we use SSL.
|
||||||
sock.write s
|
# If sock.io is an SSLSocket, copy_stream will hit SSL_write()
|
||||||
end
|
IO.copy_stream(f, sock.io)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user