diff --git a/lib/rack/reverse_proxy.rb b/lib/rack/reverse_proxy.rb index 55d5419..b6e0f8d 100644 --- a/lib/rack/reverse_proxy.rb +++ b/lib/rack/reverse_proxy.rb @@ -3,6 +3,7 @@ require "rack-proxy" require "rack/reverse_proxy_matcher" require "rack/exception" +require "rack/reverse_proxy/http_streaming_response" module Rack class ReverseProxy @@ -72,7 +73,7 @@ def proxy(env, source_request, matcher) 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.set_read_timeout(options[:timeout]) if options[:timeout].to_i > 0 target_response.use_ssl = "https" == uri.scheme diff --git a/lib/rack/reverse_proxy/http_streaming_response.rb b/lib/rack/reverse_proxy/http_streaming_response.rb new file mode 100644 index 0000000..2e43b97 --- /dev/null +++ b/lib/rack/reverse_proxy/http_streaming_response.rb @@ -0,0 +1,7 @@ +module Rack + class HttpStreamingResponse + def set_read_timeout(value) + self.read_timeout = value + end + end +end diff --git a/lib/rack/reverse_proxy_matcher.rb b/lib/rack/reverse_proxy_matcher.rb index 6afacba..7044580 100644 --- a/lib/rack/reverse_proxy_matcher.rb +++ b/lib/rack/reverse_proxy_matcher.rb @@ -1,6 +1,6 @@ module Rack class ReverseProxyMatcher - def initialize(matcher,url=nil,options) + def initialize(matcher, url=nil, options={}) @default_url=url @url=url @options=options diff --git a/spec/rack/reverse_proxy_spec.rb b/spec/rack/reverse_proxy_spec.rb index adfcbdd..5186743 100644 --- a/spec/rack/reverse_proxy_spec.rb +++ b/spec/rack/reverse_proxy_spec.rb @@ -89,7 +89,7 @@ def app 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) + Rack::HttpStreamingResponse.any_instance.should_receive(:set_read_timeout).with(99) get '/test/slow' end end @@ -103,7 +103,7 @@ def app 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=) + Rack::HttpStreamingResponse.any_instance.should_not_receive(:set_read_timeout) get '/test/slow' end end @@ -324,9 +324,9 @@ def app it "should proxy requests when a pattern is matched" do stub_request(:get, 'http://users-example.com/users?user=omer').to_return({:body => "User App"}) - get '/test', user: "mark" + get '/test', :user => "mark" last_response.body.should == "Dummy App" - get '/users', user: 'omer' + get '/users', :user => 'omer' last_response.body.should == "User App" end end