Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/rack/reverse_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
7 changes: 7 additions & 0 deletions lib/rack/reverse_proxy/http_streaming_response.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module Rack
class HttpStreamingResponse
def set_read_timeout(value)
self.read_timeout = value
end
end
end
2 changes: 1 addition & 1 deletion lib/rack/reverse_proxy_matcher.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 4 additions & 4 deletions spec/rack/reverse_proxy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down