Skip to content

Commit 1fc1ea6

Browse files
committed
don't modify Location if has no host
e.g. "users.php?update=add&id=16" in wordpress
1 parent 9a92a99 commit 1fc1ea6

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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)