summaryrefslogtreecommitdiff
path: root/chef/lib/chef/rest.rb
diff options
context:
space:
mode:
Diffstat (limited to 'chef/lib/chef/rest.rb')
-rw-r--r--chef/lib/chef/rest.rb14
1 files changed, 7 insertions, 7 deletions
diff --git a/chef/lib/chef/rest.rb b/chef/lib/chef/rest.rb
index b721a1bd27..052fa2a513 100644
--- a/chef/lib/chef/rest.rb
+++ b/chef/lib/chef/rest.rb
@@ -22,7 +22,7 @@
require 'net/https'
require 'uri'
-require 'json'
+require 'chef/json'
require 'tempfile'
require 'chef/api_client'
require 'chef/rest/auth_credentials'
@@ -162,7 +162,7 @@ class Chef
#
# Will return the body of the response on success.
def run_request(method, url, headers={}, data=false, limit=nil, raw=false)
- json_body = data ? data.to_json : nil
+ json_body = data ? Chef::JSON.to_json(data) : nil
headers = build_headers(method, url, headers, json_body, raw)
tf = nil
@@ -180,7 +180,7 @@ class Chef
if res.kind_of?(Net::HTTPSuccess)
if res['content-type'] =~ /json/
response_body = res.body.chomp
- JSON.parse(response_body)
+ Chef::JSON.from_json(response_body)
else
if method == :HEAD
true
@@ -196,7 +196,7 @@ class Chef
false
else
if res['content-type'] =~ /json/
- exception = JSON.parse(res.body)
+ exception = Chef::JSON.from_json(res.body)
msg = "HTTP Request Returned #{res.code} #{res.message}: "
msg << (exception["error"].respond_to?(:join) ? exception["error"].join(", ") : exception["error"].to_s)
Chef::Log.warn(msg)
@@ -208,7 +208,7 @@ class Chef
# Runs an HTTP request to a JSON API. File Download not supported.
def api_request(method, url, headers={}, data=false)
- json_body = data ? data.to_json : nil
+ json_body = data ? Chef::JSON.to_json(data) : nil
headers = build_headers(method, url, headers, json_body)
retriable_rest_request(method, url, json_body, headers) do |rest_request|
@@ -216,7 +216,7 @@ class Chef
if response.kind_of?(Net::HTTPSuccess)
if response['content-type'] =~ /json/
- JSON.parse(response.body.chomp)
+ Chef::JSON.from_json(response.body.chomp)
else
Chef::Log.warn("Expected JSON response, but got content-type '#{response['content-type']}'")
response.body
@@ -225,7 +225,7 @@ class Chef
follow_redirect {api_request(:GET, create_url(redirect_location))}
else
if response['content-type'] =~ /json/
- exception = JSON.parse(response.body)
+ exception = Chef::JSON.from_json(response.body)
msg = "HTTP Request Returned #{response.code} #{response.message}: "
msg << (exception["error"].respond_to?(:join) ? exception["error"].join(", ") : exception["error"].to_s)
Chef::Log.warn(msg)