    # File lib/chef/rest.rb, line 168
        def run_request(method, url, headers={}, data=false, limit=nil, raw=false)
          json_body = data ? Chef::JSONCompat.to_json(data) : nil
          # Force encoding to binary to fix SSL related EOFErrors
          # cf. http://tickets.opscode.com/browse/CHEF-2363
          # http://redmine.ruby-lang.org/issues/5233
          json_body.force_encoding(Encoding::BINARY) if json_body.respond_to?(:force_encoding)
          headers = build_headers(method, url, headers, json_body, raw)

          tf = nil

          retriable_rest_request(method, url, json_body, headers) do |rest_request|

            res = rest_request.call do |response|
              if raw
                tf = stream_to_tempfile(url, response)
              else
                response.read_body
              end
            end

            if res.kind_of?(Net::HTTPSuccess)
              if res['content-type'] =~ /json/
                response_body = res.body.chomp
                Chef::JSONCompat.from_json(response_body)
              else
                if method == :HEAD
                  true
                elsif raw
                  tf
                else
                  res.body
                end
              end
            elsif res.kind_of?(Net::HTTPFound) or res.kind_of?(Net::HTTPMovedPermanently)
              follow_redirect {run_request(method, create_url(res['location']), headers, false, nil, raw)}
            elsif res.kind_of?(Net::HTTPNotModified)
              false
            else
              if res['content-type'] =~ /json/
                exception = Chef::JSONCompat.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)
              end
              res.error!
            end
          end
        end