Class: RedHatSupportLib::Network::HttpRequest

Inherits:
RestClient::Request
  • Object
show all
Defined in:
lib/network/http_request.rb

Overview

This HACK class allows us to set proxy on per connection basis when using RestClient libraries 1.6.x and below THINGS MAY BREAK when we upgrade RestClient.….

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ HttpRequest

Returns a new instance of HttpRequest.



12
13
14
15
16
17
# File 'lib/network/http_request.rb', line 12

def initialize (args={})
  if args[:proxy]
    @proxy = args[:proxy]
  end
  super(args)
end

Class Method Details

.execute(args, &block) ⇒ Object



19
20
21
# File 'lib/network/http_request.rb', line 19

def self.execute(args, & block)
  new(args).execute(& block)
end

Instance Method Details

#net_http_classObject



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/network/http_request.rb', line 42

def net_http_class
  p = proxy_uri
  if p
    host = URI.decode(p.hostname) if p.hostname
    user = URI.decode(p.user) if p.user
    password = URI.decode(p.password) if p.password
    Net::HTTP::Proxy(host,p.port, user, password)
  else
    Net::HTTP
  end
end

#proxy_uriURI?

The proxy URI for this request. If ‘:proxy` was provided on this request, use it over `RestClient.proxy`.

Returns:

  • (URI, nil)


28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/network/http_request.rb', line 28

def proxy_uri
  if defined?(@proxy)
    if @proxy
      URI.parse(@proxy)
    else
      nil
    end
  elsif RestClient.proxy
    URI.parse(RestClient.proxy)
  else
    nil
  end
end