Method: DatadogAPIClient::APIClient#build_request
- Defined in:
- lib/datadog_api_client/api_client.rb
#build_request(http_method, path, opts = {}) ⇒ HTTParty::Request
Build the HTTP request
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
# File 'lib/datadog_api_client/api_client.rb', line 175 def build_request(http_method, path, opts = {}) url = build_request_url(path, opts) header_params = @default_headers.merge(opts[:header_params] || {}) query_params = opts[:query_params] || {} form_params = opts[:form_params] || {} update_params_for_auth! header_params, query_params, opts[:auth_names] # set ssl_verifyhosts option based on @config.verify_ssl_host (true/false) _verify_ssl_host = @config.verify_ssl_host ? 2 : 0 req_opts = { :method => http_method, :headers => header_params, :query => transform_hash(query_params), :timeout => @config.timeout, :verify_peer => @config.verify_ssl, :verify => _verify_ssl_host, :verbose => @config.debugging, :http_proxyaddr => @config.http_proxyaddr, :http_proxyport => @config.http_proxyport, :http_proxyuser => @config.http_proxyuser, :http_proxypass => @config.http_proxypass } req_opts[:pem] = File.read(@config.cert_file) if @config.cert_file req_opts[:pem_password] = File.read(@config.key_file) if @config.key_file req_opts[:query_string_normalizer] = opts[:query_string_normalizer] if opts[:query_string_normalizer] opts[:stream_body] = true if opts[:return_type] == 'File' # set custom cert, if provided req_opts[:ssl_ca_file] = File.read(@config.ssl_ca_cert) if @config.ssl_ca_cert if @config.debugging @config.logger.debug "HTTP request url\n#{url}\n" @config.logger.debug "HTTP request header\n#{sanitize_request_header(header_params)}\n" end if ["POST", "PATCH", "PUT", "DELETE"].include?(http_method.const_get(:METHOD)) req_body = build_request_body(header_params, form_params, opts[:body]) req_opts.update :body => req_body if @config.debugging @config.logger.debug "HTTP request body ~BEGIN~\n#{req_body}\n~END~\n" end end HTTParty::Request.new(http_method, url, req_opts) end |