Skip to content

Commit

Permalink
Merge pull request #492 from capicue/redirect-uri
Browse files Browse the repository at this point in the history
Deal with network-path reference redirects
  • Loading branch information
greatuserongithub committed Sep 12, 2016
2 parents 1a1bca9 + 3e5edd4 commit 247d541
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/httparty/request.rb
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions spec/httparty/request_spec.rb
Expand Up @@ -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
Expand Down

0 comments on commit 247d541

Please sign in to comment.