Skip to content
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
5 changes: 3 additions & 2 deletions lib/rack/reverse_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class ReverseProxy
def initialize(app = nil, &b)
@app = app || lambda {|env| [404, [], []] }
@matchers = []
@global_options = {:preserve_host => true, :matching => :all, :verify_ssl => true}
@global_options = {:preserve_host => true, :matching => :all, :verify_ssl => true, :debug => false}
instance_eval &b if block_given?
end

Expand All @@ -24,7 +24,8 @@ def call(env)
end
}
headers['HOST'] = uri.host if all_opts[:preserve_host]

puts "Proxying #{rackreq.url} => #{uri} (Headers: #{headers.inspect})" if all_opts[:debug]

session = Net::HTTP.new(uri.host, uri.port)
session.read_timeout=all_opts[:timeout] if all_opts[:timeout]

Expand Down
14 changes: 14 additions & 0 deletions spec/rack/reverse_proxy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,20 @@ def app
last_response.body.should == "secured content"
end
end

describe "with debug turned on" do
def app
@app ||= Rack::ReverseProxy.new(dummy_app) do
reverse_proxy '/test', 'http://example.com/', {:debug => true}
end
end

it "should print debugging information" do
stub_request(:any, 'example.com/test/stuff')
app.should_receive(:puts).with("Proxying http://example.org/test/stuff => http://example.com/test/stuff (Headers: {\"HOST\"=>\"example.com\", \"COOKIE\"=>\"\", \"X-Forwarded-Host\"=>\"example.org\"})")
get '/test/stuff'
end
end

describe "with ambiguous routes and all matching" do
def app
Expand Down