Module: Ji2p::Package::ProxySupport

Extended by:
ProxySupport
Included in:
ProxySupport
Defined in:
lib/ji2p/package/proxy_support.rb

Instance Method Summary collapse

Instance Method Details

#apply_env_proxy_settings(settings) ⇒ Object

Apply HTTP_PROXY and HTTPS_PROXY to the current environment this will be used by any JRUBY calls



13
14
15
16
17
18
19
20
# File 'lib/ji2p/package/proxy_support.rb', line 13

def apply_env_proxy_settings(settings)
  $stderr.puts("Using proxy #{settings}") if ENV["DEBUG"]
  scheme = settings[:protocol].downcase
  java.lang.System.setProperty("#{scheme}.proxyHost", settings[:host])
  java.lang.System.setProperty("#{scheme}.proxyPort", settings[:port].to_s)
  java.lang.System.setProperty("#{scheme}.proxyUsername", settings[:username].to_s)
  java.lang.System.setProperty("#{scheme}.proxyPassword", settings[:password].to_s)
end

#extract_proxy_values_from_uri(proxy_uri) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/ji2p/package/proxy_support.rb', line 22

def extract_proxy_values_from_uri(proxy_uri)
  {
    :protocol => proxy_uri.scheme,
    :host => proxy_uri.host,
    :port => proxy_uri.port,
    :username => proxy_uri.user,
    :password => proxy_uri.password
  }
end

#get_proxy(key) ⇒ Object



41
42
43
# File 'lib/ji2p/package/proxy_support.rb', line 41

def get_proxy(key)
  ENV[key.downcase] || ENV[key.upcase]
end

#parse_proxy_string(proxy_string) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/ji2p/package/proxy_support.rb', line 32

def parse_proxy_string(proxy_string)
  proxy_uri = URI.parse(proxy_string)
  if proxy_uri.kind_of?(URI::HTTP) # URI::HTTPS is already a subclass of URI::HTTP
    proxy_uri
  else
    raise "Invalid proxy `#{proxy_uri}`. The URI is not HTTP/HTTPS."
  end
end

#proxy_string_exists?(proxy) ⇒ Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/ji2p/package/proxy_support.rb', line 45

def proxy_string_exists?(proxy)
  !proxy.nil? && !proxy.strip.empty?
end