Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ruby's OpenURI supports http_proxy and no_proxy (since 2.5), so no need to carry our own implementation of it. What's left is simplication of exception handling, but I'm not so sure which exceptions are actually left to be thrown
- Loading branch information
Showing
4 changed files
with
16 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,19 @@ | ||
module Project::RemoteURL | ||
|
||
def load(remote_uri, path) | ||
uri = URI.parse(remote_uri + path) | ||
http = nil | ||
content = nil | ||
proxyuri = ENV['http_proxy'] | ||
proxyuri = CONFIG['http_proxy'] if CONFIG['http_proxy'].present? | ||
noproxy = ENV['no_proxy'] | ||
noproxy = CONFIG['no_proxy'] if CONFIG['no_proxy'].present? | ||
|
||
noproxy_applies = false | ||
if noproxy | ||
np_split = noproxy.split(',') | ||
noproxy_applies = np_split.any? { |np| uri.host.end_with?(np.strip) } | ||
class Project::RemoteURL | ||
def self.load(remote_project, path) | ||
uri = URI.parse(remote_project.remoteurl + path) | ||
# prefer environment variables if set | ||
if ENV['http_proxy'].blank? | ||
ENV['http_proxy'] = Configuration.first.http_proxy | ||
end | ||
|
||
if proxyuri && noproxy_applies == false | ||
proxy = URI.parse(proxyuri) | ||
proxy_user, proxy_pass = proxy.userinfo.split(/:/) if proxy.userinfo | ||
http = Net::HTTP::Proxy(proxy.host, proxy.port, proxy_user, proxy_pass).new(uri.host, uri.port) | ||
else | ||
http = Net::HTTP.new(uri.host, uri.port) | ||
if ENV['no_proxy'].blank? | ||
ENV['no_proxy'] = Configuration.first.no_proxy | ||
end | ||
http.use_ssl = (uri.scheme == 'https') | ||
begin | ||
http.start | ||
response = http.get uri.request_uri | ||
content = response.body if response.is_a?(Net::HTTPSuccess) | ||
rescue SocketError, Errno::EINTR, Errno::EPIPE, EOFError, Net::HTTPBadResponse, IOError, Errno::ENETUNREACH, | ||
Errno::ETIMEDOUT, Errno::ECONNREFUSED, Timeout::Error => err | ||
Rails.logger.debug "#{err} when fetching #{uri}" | ||
http = nil | ||
uri.open.read | ||
rescue OpenURI::HTTPError, SocketError, Errno::EINTR, Errno::EPIPE, EOFError, Net::HTTPBadResponse, IOError, Errno::ENETUNREACH, | ||
Errno::ETIMEDOUT, Errno::ECONNREFUSED, Timeout::Error, OpenSSL::SSL::SSLError => err | ||
Rails.logger.debug "#{err} when fetching #{path} from #{remote_project.remoteurl}" | ||
nil | ||
end | ||
http.finish if http && http.started? | ||
content | ||
end | ||
|
||
end |