handle streaming requests #12

Merged
merged 1 commit into from Jan 25, 2013
View
@@ -90,9 +90,10 @@ def request(req, body = nil, &block)
scheme = use_ssl? ? "https" : "http"
prefix = "#{scheme}://#{addr_port}"
+ body_stream_contents = req.body_stream.read if req.body_stream
response = rack_request.request("#{prefix}#{req.path}",
- {:method => req.method, :input => body || req.body})
+ {:method => req.method, :input => body || req.body || body_stream_contents})
make_net_http_response(response, &block)
end
View
@@ -151,6 +151,19 @@
it_should_behave_like "a working POST request"
it_should_behave_like "a working HTTP request"
end
+
+ describe "and make a POST request with a streamed body" do
+ before do
+ Net::HTTP.start('google.com') do |http|
+ req = Net::HTTP::Post.new('/index')
+ req.body_stream = Object.new.tap{|o| def o.read; 'foo=bar'; end }
+ @response = http.request(req)
+ end
+ end
+
+ it_should_behave_like "a working POST request"
+ it_should_behave_like "a working HTTP request"
+ end
end
describe "when activating with a block" do