diff --git a/lib/rack/reverse_proxy.rb b/lib/rack/reverse_proxy.rb index 4d3de34..55d5419 100644 --- a/lib/rack/reverse_proxy.rb +++ b/lib/rack/reverse_proxy.rb @@ -71,6 +71,9 @@ def proxy(env, source_request, matcher) # Create a streaming response (the actual network communication is deferred, a.k.a. streamed) target_response = HttpStreamingResponse.new(target_request, uri.host, uri.port) + # pass the timeout configuration through + target_response.read_timeout = options[:timeout] if options[:timeout].to_i > 0 + target_response.use_ssl = "https" == uri.scheme # Let rack set the transfer-encoding header diff --git a/spec/rack/reverse_proxy_spec.rb b/spec/rack/reverse_proxy_spec.rb index ea35a55..adfcbdd 100644 --- a/spec/rack/reverse_proxy_spec.rb +++ b/spec/rack/reverse_proxy_spec.rb @@ -80,6 +80,34 @@ def app end end + describe "with timeout configuration" do + def app + Rack::ReverseProxy.new(dummy_app) do + reverse_proxy '/test/slow', 'http://example.com/', {:timeout => 99} + end + end + + it "should make request with basic auth" do + stub_request(:get, "http://example.com/test/slow") + Rack::HttpStreamingResponse.any_instance.should_receive(:read_timeout=).with(99) + get '/test/slow' + end + end + + describe "without timeout configuration" do + def app + Rack::ReverseProxy.new(dummy_app) do + reverse_proxy '/test/slow', 'http://example.com/' + end + end + + it "should make request with basic auth" do + stub_request(:get, "http://example.com/test/slow") + Rack::HttpStreamingResponse.any_instance.should_not_receive(:read_timeout=) + get '/test/slow' + end + end + describe "with basic auth turned on" do def app Rack::ReverseProxy.new(dummy_app) do