Skip to content

Instantly share code, notes, and snippets.

@redivy
Created May 19, 2010 10:29
Show Gist options
  • Save redivy/406173 to your computer and use it in GitHub Desktop.
Save redivy/406173 to your computer and use it in GitHub Desktop.
--- lib/chef/rest.rb 2010-05-19 14:25:18.000000000 +0400
+++ lib/chef/rest.rb 2010-05-19 14:26:57.000000000 +0400
@@ -178,23 +178,20 @@
end
http.read_timeout = Chef::Config[:rest_timeout]
+ json_body = data ? data.to_json : nil
headers = @default_headers.merge(headers)
-
- unless raw
- headers = headers.merge({
- 'Accept' => "application/json",
- })
+ headers['Accept'] = "application/json" unless raw
+ headers["Content-Type"] = 'application/json' if json_body
+ if method == :POST or method == :PUT
+ headers["Content-Length"] = json_body ? json_body.size.to_s : '0'
end
-
headers['X-Chef-Version'] = ::Chef::VERSION
if @cookies.has_key?("#{url.host}:#{url.port}")
headers['Cookie'] = @cookies["#{url.host}:#{url.port}"]
end
- json_body = data ? data.to_json : nil
-
if @sign_request
raise ArgumentError, "Cannot sign the request without a client name, check that :node_name is assigned" if @client_name.nil?
Chef::Log.debug("Signing the request as #{@client_name}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment