Class: NewRelic::Agent::HTTPClients::AsyncHTTPRequest

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

Constant Summary collapse

ASYNC_HTTP =
'Async::HTTP'

Constants inherited from AbstractRequest

NewRelic::Agent::HTTPClients::AbstractRequest::COLON, NewRelic::Agent::HTTPClients::AbstractRequest::LHOST, NewRelic::Agent::HTTPClients::AbstractRequest::UHOST

Instance Method Summary collapse

Constructor Details

#initialize(connection, method, url, headers) ⇒ AsyncHTTPRequest

Returns a new instance of AsyncHTTPRequest.



26
27
28
29
30
31
# File 'lib/new_relic/agent/http_clients/async_http_wrappers.rb', line 26

def initialize(connection, method, url, headers)
  @connection = connection
  @method = method
  @url = ::NewRelic::Agent::HTTPClients::URIUtil.parse_and_normalize_url(url)
  @headers = headers
end

Instance Method Details

#[](key) ⇒ Object



49
50
51
52
53
54
55
56
# File 'lib/new_relic/agent/http_clients/async_http_wrappers.rb', line 49

def [](key)
  return headers[key] unless headers.is_a?(Array)

  headers.each do |header|
    return header[1] if header[0].casecmp?(key)
  end
  nil
end

#[]=(key, value) ⇒ Object



58
59
60
61
62
63
64
# File 'lib/new_relic/agent/http_clients/async_http_wrappers.rb', line 58

def []=(key, value)
  if headers.is_a?(Array)
    headers << [key, value]
  else
    headers[key] = value
  end
end

#headersObject



70
71
72
# File 'lib/new_relic/agent/http_clients/async_http_wrappers.rb', line 70

def headers
  @headers
end

#hostObject



45
46
47
# File 'lib/new_relic/agent/http_clients/async_http_wrappers.rb', line 45

def host
  host_from_header || uri.host.to_s
end

#host_from_headerObject



39
40
41
42
43
# File 'lib/new_relic/agent/http_clients/async_http_wrappers.rb', line 39

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

#methodObject



74
75
76
# File 'lib/new_relic/agent/http_clients/async_http_wrappers.rb', line 74

def method
  @method
end

#typeObject



35
36
37
# File 'lib/new_relic/agent/http_clients/async_http_wrappers.rb', line 35

def type
  ASYNC_HTTP
end

#uriObject



66
67
68
# File 'lib/new_relic/agent/http_clients/async_http_wrappers.rb', line 66

def uri
  @url
end