Class: NewRelic::Agent::HTTPClients::EthonHTTPRequest
- Inherits:
-
AbstractRequest
- Object
- AbstractRequest
- NewRelic::Agent::HTTPClients::EthonHTTPRequest
- Defined in:
- lib/new_relic/agent/http_clients/ethon_wrappers.rb
Constant Summary collapse
- DEFAULT_ACTION =
'GET'
- DEFAULT_HOST =
'UNKNOWN_HOST'
- ETHON =
'Ethon'
- LHOST =
'host'.freeze
- UHOST =
'Host'.freeze
Instance Attribute Summary collapse
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #action_instance_var ⇒ Object
- #headers ⇒ Object
- #headers_instance_var ⇒ Object
- #host ⇒ Object
- #host_from_header ⇒ Object
-
#initialize(easy) ⇒ EthonHTTPRequest
constructor
A new instance of EthonHTTPRequest.
- #method ⇒ Object
- #type ⇒ Object
- #uri_from_easy ⇒ Object
Constructor Details
#initialize(easy) ⇒ EthonHTTPRequest
Returns a new instance of EthonHTTPRequest.
48 49 50 51 |
# File 'lib/new_relic/agent/http_clients/ethon_wrappers.rb', line 48 def initialize(easy) @easy = easy @uri = uri_from_easy end |
Instance Attribute Details
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
40 41 42 |
# File 'lib/new_relic/agent/http_clients/ethon_wrappers.rb', line 40 def uri @uri end |
Instance Method Details
#[](key) ⇒ Object
105 106 107 |
# File 'lib/new_relic/agent/http_clients/ethon_wrappers.rb', line 105 def [](key) headers[key] end |
#[]=(key, value) ⇒ Object
88 89 90 91 |
# File 'lib/new_relic/agent/http_clients/ethon_wrappers.rb', line 88 def []=(key, value) headers[key] = value @easy.headers = headers end |
#action_instance_var ⇒ Object
84 85 86 |
# File 'lib/new_relic/agent/http_clients/ethon_wrappers.rb', line 84 def action_instance_var NewRelic::Agent::Instrumentation::Ethon::Easy::ACTION_INSTANCE_VAR end |
#headers ⇒ Object
93 94 95 96 97 98 99 |
# File 'lib/new_relic/agent/http_clients/ethon_wrappers.rb', line 93 def headers @headers ||= if @easy.instance_variable_defined?(headers_instance_var) @easy.instance_variable_get(headers_instance_var) else {} end end |
#headers_instance_var ⇒ Object
101 102 103 |
# File 'lib/new_relic/agent/http_clients/ethon_wrappers.rb', line 101 def headers_instance_var NewRelic::Agent::Instrumentation::Ethon::Easy::HEADERS_INSTANCE_VAR end |
#host ⇒ Object
74 75 76 |
# File 'lib/new_relic/agent/http_clients/ethon_wrappers.rb', line 74 def host host_from_header || uri.host&.downcase || DEFAULT_HOST end |
#host_from_header ⇒ Object
57 58 59 |
# File 'lib/new_relic/agent/http_clients/ethon_wrappers.rb', line 57 def host_from_header self[LHOST] || self[UHOST] end |
#method ⇒ Object
78 79 80 81 82 |
# File 'lib/new_relic/agent/http_clients/ethon_wrappers.rb', line 78 def method return DEFAULT_ACTION unless @easy.instance_variable_defined?(action_instance_var) @easy.instance_variable_get(action_instance_var) end |
#type ⇒ Object
53 54 55 |
# File 'lib/new_relic/agent/http_clients/ethon_wrappers.rb', line 53 def type ETHON end |
#uri_from_easy ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/new_relic/agent/http_clients/ethon_wrappers.rb', line 61 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.}") URI.parse(NewRelic::EMPTY_STR) end end |