Class: NewRelic::Agent::HTTPClients::NetHTTPRequest

Inherits:
AbstractRequest show all
Defined in:
lib/new_relic/agent/http_clients/net_http_wrappers.rb

Constant Summary collapse

NET_HTTP =
'Net::HTTP'

Constants inherited from AbstractRequest

AbstractRequest::COLON, AbstractRequest::LHOST, AbstractRequest::UHOST

Instance Method Summary collapse

Constructor Details

#initialize(connection, request) ⇒ NetHTTPRequest

Returns a new instance of NetHTTPRequest.



22
23
24
25
# File 'lib/new_relic/agent/http_clients/net_http_wrappers.rb', line 22

def initialize(connection, request)
  @connection = connection
  @request = request
end

Instance Method Details

#[](key) ⇒ Object



47
48
49
# File 'lib/new_relic/agent/http_clients/net_http_wrappers.rb', line 47

def [](key)
  @request[key]
end

#[]=(key, value) ⇒ Object



51
52
53
# File 'lib/new_relic/agent/http_clients/net_http_wrappers.rb', line 51

def []=(key, value)
  @request[key] = value
end

#headersObject



72
73
74
# File 'lib/new_relic/agent/http_clients/net_http_wrappers.rb', line 72

def headers
  @request.instance_variable_get(:@header)
end

#hostObject



39
40
41
# File 'lib/new_relic/agent/http_clients/net_http_wrappers.rb', line 39

def host
  host_from_header || @connection.address
end

#host_from_headerObject



33
34
35
36
37
# File 'lib/new_relic/agent/http_clients/net_http_wrappers.rb', line 33

def host_from_header
  if hostname = self[LHOST]
    hostname.split(COLON).first
  end
end

#methodObject



43
44
45
# File 'lib/new_relic/agent/http_clients/net_http_wrappers.rb', line 43

def method
  @request.method
end

#typeObject



29
30
31
# File 'lib/new_relic/agent/http_clients/net_http_wrappers.rb', line 29

def type
  NET_HTTP
end

#uriObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/new_relic/agent/http_clients/net_http_wrappers.rb', line 55

def uri
  case @request.path
  when /^https?:\/\//
    ::NewRelic::Agent::HTTPClients::URIUtil.parse_and_normalize_url(@request.path)
  else
    connection_address = @connection.address
    if Resolv::IPv6::Regex.match?(connection_address)
      connection_address = "[#{connection_address}]"
    end

    scheme = @connection.use_ssl? ? 'https' : 'http'
    ::NewRelic::Agent::HTTPClients::URIUtil.parse_and_normalize_url(
      "#{scheme}://#{connection_address}:#{@connection.port}#{@request.path}"
    )
  end
end