diff options
author | Thom May <thom@chef.io> | 2015-12-02 12:19:33 +0000 |
---|---|---|
committer | Thom May <thom@chef.io> | 2016-01-11 15:40:42 +0000 |
commit | d99e306a41b1402209d320cb7119b12a3bbb962f (patch) | |
tree | f65940702826deb991e6198967d3e9e96cb2857a /lib/chef/server_api.rb | |
parent | 1b71aeb423b009f6d1a44215c89e9976957b47e9 (diff) | |
download | chef-d99e306a41b1402209d320cb7119b12a3bbb962f.tar.gz |
Convert all uses of Chef::REST to Chef::ServerAPItm/no_more_rest
In the process, stop auto-expanding JSON in the HTTP client, and let
individual classes control that themselves.
Fixes #2737, Fixes #3518
Diffstat (limited to 'lib/chef/server_api.rb')
-rw-r--r-- | lib/chef/server_api.rb | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/chef/server_api.rb b/lib/chef/server_api.rb index 764296f8c8..6c864d53fb 100644 --- a/lib/chef/server_api.rb +++ b/lib/chef/server_api.rb @@ -23,6 +23,7 @@ require 'chef/http/decompressor' require 'chef/http/json_input' require 'chef/http/json_output' require 'chef/http/remote_request_id' +require 'chef/http/validate_content_length' class Chef class ServerAPI < Chef::HTTP @@ -31,6 +32,7 @@ class Chef options[:client_name] ||= Chef::Config[:node_name] options[:signing_key_filename] ||= Chef::Config[:client_key] options[:signing_key_filename] = nil if chef_zero_uri?(url) + options[:inflate_json_class] = false super(url, options) end @@ -40,6 +42,30 @@ class Chef use Chef::HTTP::Decompressor use Chef::HTTP::Authenticator use Chef::HTTP::RemoteRequestID + + # ValidateContentLength should come after Decompressor + # because the order of middlewares is reversed when handling + # responses. + use Chef::HTTP::ValidateContentLength + + # Makes an HTTP request to +path+ with the given +method+, +headers+, and + # +data+ (if applicable). Does not apply any middleware, besides that + # needed for Authentication. + def raw_request(method, path, headers={}, data=false) + url = create_url(path) + method, url, headers, data = Chef::HTTP::Authenticator.new(options).handle_request(method, url, headers, data) + method, url, headers, data = Chef::HTTP::RemoteRequestID.new(options).handle_request(method, url, headers, data) + response, rest_request, return_value = send_http_request(method, url, headers, data) + response.error! unless success_response?(response) + return_value + rescue Exception => exception + log_failed_request(response, return_value) unless response.nil? + + if exception.respond_to?(:chef_rest_request=) + exception.chef_rest_request = rest_request + end + raise + end end end |