Class: AppMap::Handler::HTTPClientRequest

Inherits:
Event::MethodEvent show all
Defined in:
lib/appmap/handler/net_http_handler.rb

Constant Summary

Constants inherited from Event::MethodEvent

Event::MethodEvent::MAX_ARRAY_ENUMERATION, Event::MethodEvent::MAX_HASH_ENUMERATION, Event::MethodEvent::MAX_STRING_LENGTH

Constants included from ValueInspector

ValueInspector::MAX_ARRAY_ELEMENTS, ValueInspector::MAX_DEPTH

Instance Attribute Summary collapse

Attributes inherited from Event::MethodEventStruct

#event, #id, #thread_id

Instance Method Summary collapse

Methods inherited from Event::MethodEvent

add_schema, add_size, build_from_invocation, custom_display_string, default_display_string, display_string, encode_display_string, #ready?

Methods included from ValueInspector

#best_class_name, #detect_schema, #detect_size

Constructor Details

#initialize(http, request) ⇒ HTTPClientRequest

Returns a new instance of HTTPClientRequest.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/appmap/handler/net_http_handler.rb', line 13

def initialize(http, request)
  super AppMap::Event.next_id_counter, :call, Thread.current.object_id

  path, query = request.path.split('?')
  query ||= ''

  protocol = http.use_ssl? ? 'https' : 'http'
  port = if http.use_ssl? && http.port == 443
    nil
  elsif !http.use_ssl? && http.port == 80
    nil
  else
    ":#{http.port}"
  end

  url = [ protocol, '://', http.address, port, path ].compact.join

  self.request_method = request.method
  self.url = url
  self.headers = NetHTTPHandler.copy_headers(request)
  self.params = Rack::Utils.parse_nested_query(query)
end

Instance Attribute Details

#headersObject

Returns the value of attribute headers.



11
12
13
# File 'lib/appmap/handler/net_http_handler.rb', line 11

def headers
  @headers
end

#paramsObject

Returns the value of attribute params.



11
12
13
# File 'lib/appmap/handler/net_http_handler.rb', line 11

def params
  @params
end

#request_methodObject

Returns the value of attribute request_method.



11
12
13
# File 'lib/appmap/handler/net_http_handler.rb', line 11

def request_method
  @request_method
end

#urlObject

Returns the value of attribute url.



11
12
13
# File 'lib/appmap/handler/net_http_handler.rb', line 11

def url
  @url
end

Instance Method Details

#to_hObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/appmap/handler/net_http_handler.rb', line 36

def to_h
  super.tap do |h|
    h[:http_client_request] = {
      request_method: request_method,
      url: url,
      headers: headers
    }.compact

    unless Util.blank?(params)
      h[:message] = params.keys.map do |key|
        val = params[key]
        {
          name: key,
          class: val.class.name,
          value: self.class.display_string(val),
          object_id: val.__id__,
        }
      end
    end
  end
end