Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added/fixed support for the timeout option so the documentation in th… #52

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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: 3 additions & 0 deletions lib/rack/reverse_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 28 additions & 0 deletions spec/rack/reverse_proxy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down