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'
LHOST =
'host'
UHOST =
'Host'
COLON =
':'

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



52
53
54
55
56
57
58
59
# File 'lib/new_relic/agent/http_clients/async_http_wrappers.rb', line 52

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



61
62
63
64
65
66
67
# File 'lib/new_relic/agent/http_clients/async_http_wrappers.rb', line 61

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

#headersObject



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

def headers
  @headers
end

#hostObject



48
49
50
# File 'lib/new_relic/agent/http_clients/async_http_wrappers.rb', line 48

def host
  host_from_header || uri.host.to_s
end

#host_from_headerObject



42
43
44
45
46
# File 'lib/new_relic/agent/http_clients/async_http_wrappers.rb', line 42

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

#methodObject



77
78
79
# File 'lib/new_relic/agent/http_clients/async_http_wrappers.rb', line 77

def method
  @method
end

#typeObject



38
39
40
# File 'lib/new_relic/agent/http_clients/async_http_wrappers.rb', line 38

def type
  ASYNC_HTTP
end

#uriObject



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

def uri
  @url
end