Skip to content

Commit 5066dc6

Browse files
committed
Merge pull request #1 from waterlink/usertesting/pull-52
added/fixed support for the timeout option so the documentation in th…
2 parents 8f8871e + 2e3ace7 commit 5066dc6

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

lib/rack/reverse_proxy.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ def proxy(env, source_request, matcher)
7171
# Create a streaming response (the actual network communication is deferred, a.k.a. streamed)
7272
target_response = HttpStreamingResponse.new(target_request, uri.host, uri.port)
7373

74+
# pass the timeout configuration through
75+
target_response.read_timeout = options[:timeout] if options[:timeout].to_i > 0
76+
7477
target_response.use_ssl = "https" == uri.scheme
7578

7679
# Let rack set the transfer-encoding header

spec/rack/reverse_proxy_spec.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,34 @@ def app
8080
end
8181
end
8282

83+
describe "with timeout configuration" do
84+
def app
85+
Rack::ReverseProxy.new(dummy_app) do
86+
reverse_proxy '/test/slow', 'http://example.com/', {:timeout => 99}
87+
end
88+
end
89+
90+
it "should make request with basic auth" do
91+
stub_request(:get, "http://example.com/test/slow")
92+
Rack::HttpStreamingResponse.any_instance.should_receive(:read_timeout=).with(99)
93+
get '/test/slow'
94+
end
95+
end
96+
97+
describe "without timeout configuration" do
98+
def app
99+
Rack::ReverseProxy.new(dummy_app) do
100+
reverse_proxy '/test/slow', 'http://example.com/'
101+
end
102+
end
103+
104+
it "should make request with basic auth" do
105+
stub_request(:get, "http://example.com/test/slow")
106+
Rack::HttpStreamingResponse.any_instance.should_not_receive(:read_timeout=)
107+
get '/test/slow'
108+
end
109+
end
110+
83111
describe "with basic auth turned on" do
84112
def app
85113
Rack::ReverseProxy.new(dummy_app) do

0 commit comments

Comments
 (0)