Class: Net::HTTP
- Inherits:
-
Object
- Object
- Net::HTTP
- Defined in:
- lib/s3sync/HTTPStreaming.rb
Overview
Allow request body to be an IO stream Allow an IO stream argument to stream the response body out
Defined Under Namespace
Classes: Delete
Instance Method Summary collapse
- #_HTTPStreaming_request ⇒ Object
- #request(req, body = nil, streamResponseBodyTo = nil, &block) ⇒ Object
Instance Method Details
#_HTTPStreaming_request ⇒ Object
26 |
# File 'lib/s3sync/HTTPStreaming.rb', line 26 alias _HTTPStreaming_request request |
#request(req, body = nil, streamResponseBodyTo = nil, &block) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/s3sync/HTTPStreaming.rb', line 28 def request(req, body = nil, streamResponseBodyTo = nil, &block) if not block_given? and streamResponseBodyTo and streamResponseBodyTo.respond_to?(:write) $stderr.puts "Response using streaming" if $HTTPStreamingDebug # this might be a retry, we should make sure the stream is at its beginning streamResponseBodyTo.rewind if streamResponseBodyTo.respond_to?(:rewind) and streamResponseBodyTo != $stdout block = proc do |res| res.read_body do |chunk| streamResponseBodyTo.write(chunk) end end end if body != nil && body.respond_to?(:read) $stderr.puts "Request using streaming" if $HTTPStreamingDebug # this might be a retry, we should make sure the stream is at its beginning body.rewind if body.respond_to?(:rewind) req.body_stream = body return _HTTPStreaming_request(req, nil, &block) else return _HTTPStreaming_request(req, body, &block) end end |