Skip to content

Commit 233ea26

Browse files
authored
Merge pull request jaswope#46 from jjb/do-not-replace-location-without-host
Do not replace location without host
2 parents 4de4bac + 1fc1ea6 commit 233ea26

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

lib/rack_reverse_proxy/roundtrip.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def response_location
179179
end
180180

181181
def need_replace_location?
182-
response_headers["Location"] && options[:replace_response_host]
182+
response_headers["Location"] && options[:replace_response_host] && response_location.host
183183
end
184184

185185
def setup_request

spec/rack/reverse_proxy_spec.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ def app
322322
end
323323
end
324324

325-
describe "with preserve response host turned on" do
325+
describe "with replace response host turned on" do
326326
def app
327327
Rack::ReverseProxy.new(dummy_app) do
328328
reverse_proxy "/test", "http://example.com/", :replace_response_host => true
@@ -354,6 +354,14 @@ def app
354354
get "https://example.com/test/stuff"
355355
expect(last_response.headers["location"]).to eq("https://example.com/bar")
356356
end
357+
358+
it "doesn't replaces the location response header if it has no host" do
359+
stub_request(:get, "http://example.com/test/stuff").to_return(
360+
:headers => { "location" => "/bar" }
361+
)
362+
get "http://example.com/test/stuff"
363+
expect(last_response.headers["location"]).to eq("/bar")
364+
end
357365
end
358366

359367
describe "with ambiguous routes and all matching" do

0 commit comments

Comments
 (0)