Method: Chef::HTTP#request

Defined in:
lib/chef/http.rb

#request(method, path, headers = {}, data = false) ⇒ Object

Makes an HTTP request to path with the given method, headers, and data (if applicable).



150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/chef/http.rb', line 150

def request(method, path, headers = {}, data = false)
  http_attempts ||= 0
  url = create_url(path)
  processed_method, url, processed_headers, processed_data = apply_request_middleware(method, url, headers, data)

  response, rest_request, return_value = send_http_request(processed_method, url, processed_headers, processed_data)
  response, rest_request, return_value = apply_response_middleware(response, rest_request, return_value)

  response.error! unless success_response?(response)
  return_value

rescue Net::HTTPClientException => e
  http_attempts += 1
  response = e.response
  if response.is_a?(Net::HTTPNotAcceptable) && version_retries - http_attempts >= 0
    Chef::Log.trace("Negotiating protocol version with #{url}, retry #{http_attempts}/#{version_retries}")
    retry
  else
    raise
  end
rescue Exception => exception
  log_failed_request(response, return_value) unless response.nil?
  raise
end