Class: Net::HTTP

Inherits:
Object
  • Object
show all
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

Instance Method Details

#_HTTPStreaming_requestObject



25
# File 'lib/s3sync/HTTPStreaming.rb', line 25

alias _HTTPStreaming_request request

#request(req, body = nil, streamResponseBodyTo = nil, &block) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/s3sync/HTTPStreaming.rb', line 27

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