Module: CFoundry::ProxyOptions

Included in:
BaseClient, RestClient
Defined in:
lib/cfoundry/concerns/proxy_options.rb

Instance Method Summary collapse

Instance Method Details

#proxy_options_for(uri) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/cfoundry/concerns/proxy_options.rb', line 3

def proxy_options_for(uri)
  ssl = uri.is_a?(URI::HTTPS)
  proxy_to_use = (ssl ? https_proxy : http_proxy)

  if proxy_to_use.blank?
    []
  else
    proxy_to_use = "proto://#{proxy_to_use}" unless proxy_to_use =~ /:\/\//
    proxy_uri = URI.parse(proxy_to_use)
    proxy_user, proxy_password = proxy_uri.userinfo.split(/:/) if proxy_uri.userinfo
    [proxy_uri.host, proxy_uri.port, proxy_user, proxy_password]
  end
end