1
0
Fork 0
mirror of https://github.com/jnunemaker/httparty synced 2023-03-27 23:23:07 -04:00

Deal with network-path reference redirects

fixes #491
This commit is contained in:
Stacey Touset 2016-08-24 15:19:17 -07:00
parent 6049c5e798
commit 3e5edd4cdb
2 changed files with 15 additions and 1 deletions

View file

@ -76,7 +76,13 @@ module HTTParty
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

View file

@ -230,6 +230,14 @@ RSpec.describe HTTParty::Request do
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