diff --git a/lib/httparty/request.rb b/lib/httparty/request.rb index b51075ec..04d5388f 100644 --- a/lib/httparty/request.rb +++ b/lib/httparty/request.rb @@ -76,7 +76,13 @@ def uri path.path = last_uri_host + path.path end - new_uri = path.relative? ? options[:uri_adapter].parse("#{base_uri}#{path}") : path.clone + if path.relative? && path.host + new_uri = options[:uri_adapter].parse("#{@last_uri.scheme}:#{path}") + elsif path.relative? + new_uri = options[:uri_adapter].parse("#{base_uri}#{path}") + else + new_uri = path.clone + end # avoid double query string on redirects [#12] unless redirect diff --git a/spec/httparty/request_spec.rb b/spec/httparty/request_spec.rb index a72436c2..0aa1c5d4 100644 --- a/spec/httparty/request_spec.rb +++ b/spec/httparty/request_spec.rb @@ -230,6 +230,14 @@ expect(@request.uri).to eq(URI.parse("http://example.com/bar?foo=bar")) end + + it "returns correct path when the server sets the location header to a network-path reference" do + @request.last_uri = URI.parse("https://example.com") + @request.path = URI.parse("//www.example.com") + @request.redirect = true + + expect(@request.uri).to eq(URI.parse("https://www.example.com")) + end end context "query strings" do