Class: ReeHttp::ExecuteRequest

Inherits:
Object
  • Object
show all
Includes:
Ree::FnDSL, HttpExceptions
Defined in:
lib/ree_lib/packages/ree_http/package/ree_http/functions/execute_request.rb

Constant Summary collapse

REDIRECT_CODES =
[300, 301, 302, 303, 307, 308].to_set.freeze
STRICT_SENSITIVE_CODES =
[300, 301, 302].to_set.freeze
ALWAYS_GET_CODES =
[303].to_set.freeze
METHOD_NOT_MODIFIED_CODES =
[307, 308].to_set.freeze
UNSAFE_VERBS =
%i[put delete post patch options].to_set.freeze
SEE_OTHER_ALLOWED_VERBS =
%i[get head].to_set.freeze
MAX_REDIRECT_COUNT =
10
DEFAULTS =
{
  redirects_count: MAX_REDIRECT_COUNT,
  strict_redirect_mode: true,
  timeout: DEFAULT_TIMEOUT,
  write_timeout: DEFAULT_WRITE_TIMEOUT,
  force_ssl: DEFAULT_FORCE_SSL,
}.freeze

Constants included from HttpExceptions

HttpExceptions::RedirectError, HttpExceptions::RedirectMethodError, HttpExceptions::TooManyRedirectsError

Instance Method Summary collapse

Instance Method Details

#call(request, **opts, &block) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/ree_lib/packages/ree_http/package/ree_http/functions/execute_request.rb', line 72

def call(request, **opts, &block)
  opts = DEFAULTS.merge(opts)

  requester = build_request_executor(
    request.uri,
    **slice(opts, [:timeout, :force_ssl, :ca_certs, :proxy, :write_timeout])
  )

  ReeHttp.logger.debug(
    "Sending #{request.method} request: URI #{request.uri}\n BODY: #{request.body}\n"
  )

  response = requester.start do |http|
    http.request(request, &block)
  end

  ReeHttp.logger.debug(
    "Got #{response.code} response on request URI #{request.uri}\n With BODY: #{response.body}\n"
  )

  if response.is_a?(Net::HTTPRedirection)
    return process_redirect_response(response, request, opts, &block)
  end

  response
end