Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

handle streaming requests

  • Loading branch information...
commit f3b1289ac9e3f28f71ec8967cdde3ec300dd77c1 1 parent 4c0f639
@shawndrost authored
Showing with 15 additions and 1 deletion.
  1. +2 −1  lib/artifice.rb
  2. +13 −0 spec/artifice_spec.rb
View
3  lib/artifice.rb
@@ -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
13 spec/artifice_spec.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.