summaryrefslogtreecommitdiff
path: root/lib/chef/http
diff options
context:
space:
mode:
authorJohn Keiser <jkeiser@opscode.com>2013-10-08 20:40:08 -0700
committerJohn Keiser <jkeiser@opscode.com>2013-10-09 09:21:02 -0700
commit836705dee684032baa85920c808a3eca5f5a8a87 (patch)
treeeb6373c1ee4e352ba58c8beef0ddfd194b749cf7 /lib/chef/http
parenta44352871130b3adea32c93bdaca696b518a335a (diff)
downloadchef-836705dee684032baa85920c808a3eca5f5a8a87.tar.gz
CHEF-4515: upload sometimes inflates JSON. Fix by using true raw version of Chef::REST
Diffstat (limited to 'lib/chef/http')
-rw-r--r--lib/chef/http/json_to_model_inflater.rb20
1 files changed, 18 insertions, 2 deletions
diff --git a/lib/chef/http/json_to_model_inflater.rb b/lib/chef/http/json_to_model_inflater.rb
index 0b46054510..31cd18a6b6 100644
--- a/lib/chef/http/json_to_model_inflater.rb
+++ b/lib/chef/http/json_to_model_inflater.rb
@@ -26,6 +26,9 @@ class Chef
class JSONToModelInflater
def initialize(opts={})
+ @raw_input = opts[:raw_input]
+ @raw_output = opts[:raw_output]
+ @inflate_json_class = opts.has_key?(:inflate_json_class) ? opts[:inflate_json_class] : true
end
def handle_request(method, url, headers={}, data=false)
@@ -34,7 +37,11 @@ class Chef
# Accept to the desired value before middlewares get called.
headers['Accept'] ||= "application/json"
headers["Content-Type"] = 'application/json' if data
- json_body = data ? Chef::JSONCompat.to_json(data) : nil
+ if @raw_input
+ json_body = data || nil
+ else
+ json_body = data ? Chef::JSONCompat.to_json(data) : nil
+ end
# Force encoding to binary to fix SSL related EOFErrors
# cf. http://tickets.opscode.com/browse/CHEF-2363
# http://redmine.ruby-lang.org/issues/5233
@@ -47,7 +54,16 @@ class Chef
# needed to keep conditional get stuff working correctly.
return [http_response, rest_request, return_value] if return_value == false
if http_response['content-type'] =~ /json/
- [http_response, rest_request, Chef::JSONCompat.from_json(http_response.body.chomp)]
+ if @raw_output
+ return_value = http_response.body.to_s
+ else
+ if @inflate_json_class
+ return_value = Chef::JSONCompat.from_json(http_response.body.chomp)
+ else
+ return_value = Chef::JSONCompat.from_json(http_response.body.chomp, :create_additions => false)
+ end
+ end
+ [http_response, rest_request, return_value]
else
Chef::Log.warn("Expected JSON response, but got content-type '#{http_response['content-type']}'")
return [http_response, rest_request, http_response.body.to_s]