Skip to content

Commit 93c91f5

Browse files
committed
Default to x_forwarded_host being on
1 parent 0ff9559 commit 93c91f5

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

lib/rack/reverse_proxy.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class ReverseProxy
66
def initialize(app = nil, &b)
77
@app = app || lambda {|env| [404, [], []] }
88
@matchers = []
9-
@global_options = {:preserve_host => true, :matching => :all, :verify_ssl => true}
9+
@global_options = {:preserve_host => true, :x_forwarded_host => true, :matching => :all, :verify_ssl => true}
1010
instance_eval &b if block_given?
1111
end
1212

spec/rack/reverse_proxy_spec.rb

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ def app
5656
a_request(:get, 'http://example.com/test/stuff').with(:headers => {"Host" => "example.com"}).should have_been_made
5757
end
5858

59+
it "should set the X-Forwarded-Host header to the proxying host by default" do
60+
stub_request(:any, 'example.com/test/stuff')
61+
get '/test/stuff'
62+
a_request(:get, 'http://example.com/test/stuff').with(:headers => {'X-Forwarded-Host' => 'example.org'}).should have_been_made
63+
end
64+
5965
describe "with preserve host turned off" do
6066
def app
6167
Rack::ReverseProxy.new(dummy_app) do
@@ -71,18 +77,19 @@ def app
7177
end
7278
end
7379

74-
describe "with x_forwarded_host turned on" do
80+
describe "with x_forwarded_host turned off" do
7581
def app
7682
Rack::ReverseProxy.new(dummy_app) do
77-
reverse_proxy_options :x_forwarded_host => true
83+
reverse_proxy_options :x_forwarded_host => false
7884
reverse_proxy '/test', 'http://example.com/'
7985
end
8086
end
8187

82-
it "should optionally set the X-Forwarded-Host header to the proxying host" do
88+
it "should not set the X-Forwarded-Host header to the proxying host" do
8389
stub_request(:any, 'example.com/test/stuff')
8490
get '/test/stuff'
85-
a_request(:get, 'http://example.com/test/stuff').with(:headers => {'X-Forwarded-Host' => 'example.org'}).should have_been_made
91+
a_request(:get, 'http://example.com/test/stuff').with(:headers => {'X-Forwarded-Host' => 'example.org'}).should_not have_been_made
92+
a_request(:get, 'http://example.com/test/stuff').should have_been_made
8693
end
8794
end
8895

0 commit comments

Comments
 (0)