Class: Chef::HTTP::HTTPRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/chef/http/http_request.rb

Constant Summary collapse

UA_COMMON =
"/#{::Chef::VERSION} (#{engine}-#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}; ohai-#{Ohai::VERSION}; #{RUBY_PLATFORM}; +#{ChefUtils::Dist::Org::WEBSITE})".freeze
DEFAULT_UA =
"Chef Client" + UA_COMMON
USER_AGENT =
"User-Agent"
ACCEPT_ENCODING =
"Accept-Encoding"
ENCODING_GZIP_DEFLATE =
"gzip;q=1.0,deflate;q=0.6,identity;q=0.3"
GET =
"get"
PATCH =
"patch"
PUT =
"put"
POST =
"post"
DELETE =
"delete"
HEAD =
"head"
HTTPS =
"https"
SLASH =
"/"
HOST_LOWER =
"host"
URI_SCHEME_DEFAULT_PORT =
{ "http" => 80, "https" => 443 }.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(method, url, req_body, base_headers = {}) ⇒ HTTPRequest

Returns a new instance of HTTPRequest.



81
82
83
84
85
86
# File 'lib/chef/http/http_request.rb', line 81

def initialize(method, url, req_body, base_headers = {})
  @method, @url = method, url
  @request_body = nil
  build_headers(base_headers)
  configure_http_request(req_body)
end

Instance Attribute Details

#headersObject (readonly)

Returns the value of attribute headers.



79
80
81
# File 'lib/chef/http/http_request.rb', line 79

def headers
  @headers
end

#http_requestObject (readonly)

Returns the value of attribute http_request.



79
80
81
# File 'lib/chef/http/http_request.rb', line 79

def http_request
  @http_request
end

#methodObject (readonly)

Returns the value of attribute method.



79
80
81
# File 'lib/chef/http/http_request.rb', line 79

def method
  @method
end

#urlObject (readonly)

Returns the value of attribute url.



79
80
81
# File 'lib/chef/http/http_request.rb', line 79

def url
  @url
end

Class Method Details

.user_agentObject



75
76
77
# File 'lib/chef/http/http_request.rb', line 75

def self.user_agent
  @user_agent ||= DEFAULT_UA
end

.user_agent=(ua) ⇒ Object



71
72
73
# File 'lib/chef/http/http_request.rb', line 71

def self.user_agent=(ua)
  @user_agent = ua
end

Instance Method Details

#callObject

Deprecated.

Call request on an HTTP client object instead.



109
110
111
112
113
114
115
116
# File 'lib/chef/http/http_request.rb', line 109

def call
  hide_net_http_bug do
    http_client.request(http_request) do |response|
      yield response if block_given?
      response
    end
  end
end

#configObject



118
119
120
# File 'lib/chef/http/http_request.rb', line 118

def config
  Chef::Config
end

#hostObject



88
89
90
# File 'lib/chef/http/http_request.rb', line 88

def host
  @url.hostname
end

#http_clientObject

Deprecated.

Call request on an HTTP client object instead.



123
124
125
# File 'lib/chef/http/http_request.rb', line 123

def http_client
  @http_client ||= BasicClient.new(url).http_client
end

#pathObject



104
105
106
# File 'lib/chef/http/http_request.rb', line 104

def path
  @url.path.empty? ? SLASH : @url.path
end

#portObject



96
97
98
# File 'lib/chef/http/http_request.rb', line 96

def port
  @url.port
end

#queryObject



100
101
102
# File 'lib/chef/http/http_request.rb', line 100

def query
  @url.query
end

#uri_safe_hostObject



92
93
94
# File 'lib/chef/http/http_request.rb', line 92

def uri_safe_host
  @url.host
end