Module: Pod::HTTP
- Defined in:
- lib/cocoapods-core/http.rb
Overview
Handles HTTP requests
Class Method Summary collapse
-
.get_actual_url(url, user_agent = nil) ⇒ string
Resolve potential redirects and return the final URL.
-
.validate_url(url, user_agent = nil) ⇒ REST::response
Performs validation of a URL.
Class Method Details
.get_actual_url(url, user_agent = nil) ⇒ string
Resolve potential redirects and return the final URL.
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 |
.validate_url(url, user_agent = nil) ⇒ REST::response
Performs validation of a URL
41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/cocoapods-core/http.rb', line 41 def self.validate_url(url, user_agent = nil) return nil unless url =~ /^#{URI.regexp}$/ begin url = get_actual_url(url, user_agent) resp = perform_head_request(url, user_agent) rescue SocketError, URI::InvalidURIError, REST::Error, REST::Error::Connection resp = nil end resp end |