method
fetch_http
v2_5_5 -
Show latest stable
- Class:
Gem::RemoteFetcher
fetch_http(uri, last_modified = nil, head = false, depth = 0)public
HTTP Fetcher. Dispatched by fetch_path. Use it instead.
# File lib/rubygems/remote_fetcher.rb, line 249
def fetch_http uri, last_modified = nil, head = false, depth = 0
fetch_type = head ? Net::HTTP::Head : Net::HTTP::Get
response = request uri, fetch_type, last_modified do |req|
headers.each { |k,v| req.add_field(k,v) }
end
case response
when Net::HTTPOK, Net::HTTPNotModified then
response.uri = uri if response.respond_to? :uri
head ? response : response.body
when Net::HTTPMovedPermanently, Net::HTTPFound, Net::HTTPSeeOther,
Net::HTTPTemporaryRedirect then
raise FetchError.new('too many redirects', uri) if depth > 10
unless location = response['Location']
raise FetchError.new("redirecting but no redirect location was given", uri)
end
location = URI.parse response['Location']
if https?(uri) && !https?(location)
raise FetchError.new("redirecting to non-https resource: #{location}", uri)
end
fetch_http(location, last_modified, head, depth + 1)
else
raise FetchError.new("bad response #{response.message} #{response.code}", uri)
end
end Related methods
- Instance methods
- api_endpoint
- cache_update_path
- close_all
- correct_for_windows_path
- download
- download_to_cache
- fetch_file
- fetch_http
- fetch_https
- fetch_path
- fetch_s3
- fetch_size
- https?
- request
- Class methods
- fetcher
- new
- Protected methods
-
s3_expiration -
sign_s3_url - Private methods
-
pools_for -
proxy_for