27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/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
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
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
|