Method: Pod::HTTP.get_actual_url

Defined in:
lib/cocoapods-core/http.rb

.get_actual_url(url, user_agent = nil) ⇒ string

Resolve potential redirects and return the final URL.

Returns:

  • (string)


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/cocoapods-core/http.rb', line 11

def self.get_actual_url(url, user_agent = nil)
  redirects = 0

  loop do
    response = perform_head_request(url, user_agent)

    if [301, 302, 303, 307, 308].include? response.status_code
      location = response.headers['location'].first

      if location =~ %r{://}
        url = location
      else
        url = URI.join(url, location).to_s
      end

      redirects += 1
    else
      break
    end

    break unless redirects < MAX_HTTP_REDIRECTS
  end

  url
end