Class: OneApm::Support::HTTPClients::NetHTTPRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/one_apm/support/http_clients/net_http_wrappers.rb

Instance Method Summary collapse

Constructor Details

#initialize(connection, request) ⇒ NetHTTPRequest

Returns a new instance of NetHTTPRequest.



7
8
9
10
# File 'lib/one_apm/support/http_clients/net_http_wrappers.rb', line 7

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

Instance Method Details

#[](key) ⇒ Object



32
33
34
# File 'lib/one_apm/support/http_clients/net_http_wrappers.rb', line 32

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

#[]=(key, value) ⇒ Object



36
37
38
# File 'lib/one_apm/support/http_clients/net_http_wrappers.rb', line 36

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

#bodyObject



54
55
56
# File 'lib/one_apm/support/http_clients/net_http_wrappers.rb', line 54

def body
  @request.body
end

#hostObject



16
17
18
19
20
21
22
# File 'lib/one_apm/support/http_clients/net_http_wrappers.rb', line 16

def host
  if hostname = self['host']
    hostname.split(':').first
  else
    @connection.address
  end
end

#methodObject



28
29
30
# File 'lib/one_apm/support/http_clients/net_http_wrappers.rb', line 28

def method
  @request.method
end

#paramsObject



62
63
64
# File 'lib/one_apm/support/http_clients/net_http_wrappers.rb', line 62

def params
  post_params.merge(query)
end

#portObject



24
25
26
# File 'lib/one_apm/support/http_clients/net_http_wrappers.rb', line 24

def port
  @connection.port
end

#post_paramsObject



58
59
60
# File 'lib/one_apm/support/http_clients/net_http_wrappers.rb', line 58

def post_params
  body.nil?? {} :  CGI.parse(body)
end

#queryObject



50
51
52
# File 'lib/one_apm/support/http_clients/net_http_wrappers.rb', line 50

def query
  uri.query.nil?? {} : CGI.parse(uri.query)
end

#typeObject



12
13
14
# File 'lib/one_apm/support/http_clients/net_http_wrappers.rb', line 12

def type
  'Net::HTTP'
end

#uriObject



40
41
42
43
44
45
46
47
48
# File 'lib/one_apm/support/http_clients/net_http_wrappers.rb', line 40

def uri
  case @request.path
  when /^https?:\/\//
    URI(@request.path)
  else
    scheme = @connection.use_ssl? ? 'https' : 'http'
    URI("#{scheme}://#{@connection.address}:#{@connection.port}#{@request.path}")
  end
end