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'
HOST =
'host'
COLON =
':'

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



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

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

#[]=(key, value) ⇒ Object



54
55
56
# File 'lib/new_relic/agent/http_clients/net_http_wrappers.rb', line 54

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

#headersObject



75
76
77
# File 'lib/new_relic/agent/http_clients/net_http_wrappers.rb', line 75

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

#hostObject



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

def host
  host_from_header || @connection.address
end

#host_from_headerObject



36
37
38
39
40
# File 'lib/new_relic/agent/http_clients/net_http_wrappers.rb', line 36

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

#methodObject



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

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



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

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