class NewRelic::Agent::HTTPClients::EthonHTTPRequest

Constants

DEFAULT_ACTION
DEFAULT_HOST
ETHON

Attributes

uri[R]

Public Class Methods

new(easy) click to toggle source
# File lib/new_relic/agent/http_clients/ethon_wrappers.rb, line 46
def initialize(easy)
  @easy = easy
  @uri = uri_from_easy
end

Public Instance Methods

[](key) click to toggle source
# File lib/new_relic/agent/http_clients/ethon_wrappers.rb, line 103
def [](key)
  headers[key]
end
[]=(key, value) click to toggle source
# File lib/new_relic/agent/http_clients/ethon_wrappers.rb, line 86
def []=(key, value)
  headers[key] = value
  @easy.headers = headers
end
action_instance_var() click to toggle source
# File lib/new_relic/agent/http_clients/ethon_wrappers.rb, line 82
def action_instance_var
  NewRelic::Agent::Instrumentation::Ethon::Easy::ACTION_INSTANCE_VAR
end
headers() click to toggle source
# File lib/new_relic/agent/http_clients/ethon_wrappers.rb, line 91
def headers
  @headers ||= if @easy.instance_variable_defined?(headers_instance_var)
    @easy.instance_variable_get(headers_instance_var)
  else
    {}
  end
end
headers_instance_var() click to toggle source
# File lib/new_relic/agent/http_clients/ethon_wrappers.rb, line 99
def headers_instance_var
  NewRelic::Agent::Instrumentation::Ethon::Easy::HEADERS_INSTANCE_VAR
end
host() click to toggle source
# File lib/new_relic/agent/http_clients/ethon_wrappers.rb, line 72
def host
  host_from_header || uri.host&.downcase || DEFAULT_HOST
end
host_from_header() click to toggle source
# File lib/new_relic/agent/http_clients/ethon_wrappers.rb, line 55
def host_from_header
  self[LHOST] || self[UHOST]
end
method() click to toggle source
# File lib/new_relic/agent/http_clients/ethon_wrappers.rb, line 76
def method
  return DEFAULT_ACTION unless @easy.instance_variable_defined?(action_instance_var)

  @easy.instance_variable_get(action_instance_var)
end
type() click to toggle source
# File lib/new_relic/agent/http_clients/ethon_wrappers.rb, line 51
def type
  ETHON
end
uri_from_easy() click to toggle source
# File lib/new_relic/agent/http_clients/ethon_wrappers.rb, line 59
def uri_from_easy
  # anticipate `Ethon::Easy#url` being `example.com` without a protocol
  # defined and use an 'http' protocol prefix for `URI.parse` to work
  # with the URL as desired
  url_str = @easy.url.match?(':') ? @easy.url : "http://#{@easy.url}"
  begin
    URI.parse(url_str)
  rescue URI::InvalidURIError => e
    NewRelic::Agent.logger.debug("Failed to parse URI '#{url_str}': #{e.class} - #{e.message}")
    URI.parse(NewRelic::EMPTY_STR)
  end
end