Skip to content

Commit 0ff9559

Browse files
committed
Tests for X-Forwarded-Host code
1 parent 44bd334 commit 0ff9559

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

lib/rack/reverse_proxy.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def call(env)
2525
}
2626
headers['HOST'] = uri.host if all_opts[:preserve_host]
2727
headers['X-Forwarded-Host'] = rackreq.host if all_opts[:x_forwarded_host]
28-
28+
2929
session = Net::HTTP.new(uri.host, uri.port)
3030
session.read_timeout=all_opts[:timeout] if all_opts[:timeout]
3131

spec/rack/reverse_proxy_spec.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,21 @@ def app
7171
end
7272
end
7373

74+
describe "with x_forwarded_host turned on" do
75+
def app
76+
Rack::ReverseProxy.new(dummy_app) do
77+
reverse_proxy_options :x_forwarded_host => true
78+
reverse_proxy '/test', 'http://example.com/'
79+
end
80+
end
81+
82+
it "should optionally set the X-Forwarded-Host header to the proxying host" do
83+
stub_request(:any, 'example.com/test/stuff')
84+
get '/test/stuff'
85+
a_request(:get, 'http://example.com/test/stuff').with(:headers => {'X-Forwarded-Host' => 'example.org'}).should have_been_made
86+
end
87+
end
88+
7489
describe "with basic auth turned on" do
7590
def app
7691
Rack::ReverseProxy.new(dummy_app) do

0 commit comments

Comments
 (0)