Method: Chef::HTTP::JSONInput#handle_request

Defined in:
lib/chef/http/json_input.rb

#handle_request(method, url, headers = {}, data = false) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/chef/http/json_input.rb', line 34

def handle_request(method, url, headers = {}, data = false)
  if data && should_encode_as_json?(headers)
    headers.delete_if { |key, _value| key.casecmp("content-type") == 0 }
    headers["Content-Type"] = "application/json"
    json_opts = {}
    json_opts[:validate_utf8] = opts[:validate_utf8] if opts.key?(:validate_utf8)
    data = Chef::JSONCompat.to_json(data, json_opts)
    # Force encoding to binary to fix SSL related EOFErrors
    # cf. http://tickets.opscode.com/browse/CHEF-2363
    # http://redmine.ruby-lang.org/issues/5233
    data.force_encoding(Encoding::BINARY) if data.respond_to?(:force_encoding)
  end
  [method, url, headers, data]
end