Module: Proxy::Omaha::HttpShared

Included in:
HttpDownload, HttpRequest, ReleaseProvider
Defined in:
lib/smart_proxy_omaha/http_shared.rb

Instance Method Summary collapse

Instance Method Details

#connection_factory(url, opts = {}) ⇒ Object



7
8
9
10
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
36
37
# File 'lib/smart_proxy_omaha/http_shared.rb', line 7

def connection_factory(url, opts = {})
  method = opts.fetch(:method, :get)
  uri = URI.parse(url)

  if Proxy::Omaha::Plugin.settings.proxy.to_s.empty?
    proxy_host = nil
    proxy_port = nil
  else
    proxy = URI.parse(Proxy::Omaha::Plugin.settings.proxy)
    proxy_host = proxy.host
    proxy_port = proxy.port
  end

  http = Net::HTTP.new(uri.host, uri.port, proxy_host, proxy_port)

  if uri.scheme == 'https'
    http.use_ssl = true
  end

  request_class = case method
                    when :get
                      Net::HTTP::Get
                    when :head
                      Net::HTTP::Head
                    else
                      raise "Unknown request class"
                    end
  request = request_class.new(uri.request_uri)

  [http, request]
end