lib/appmap/rails/request_handler.rb in appmap-0.44.0 vs lib/appmap/rails/request_handler.rb in appmap-0.45.0

- old
+ new

@@ -4,40 +4,20 @@ require 'appmap/hook' module AppMap module Rails module RequestHandler - # Host and User-Agent will just introduce needless variation. - # Content-Type and Authorization get their own fields in the request. - IGNORE_HEADERS = %w[host user_agent content_type authorization].map(&:upcase).map {|h| "HTTP_#{h}"}.freeze - - class << self - def selected_headers(env) - # Rack prepends HTTP_ to all client-sent headers. - matching_headers = env - .select { |k,v| k.start_with? 'HTTP_'} - .reject { |k,v| IGNORE_HEADERS.member?(k) } - .reject { |k,v| v.blank? } - .each_with_object({}) do |kv, memo| - key = kv[0].sub(/^HTTP_/, '').split('_').map(&:capitalize).join('-') - value = kv[1] - memo[key] = value - end - matching_headers.blank? ? nil : matching_headers - end - end - class HTTPServerRequest < AppMap::Event::MethodEvent attr_accessor :normalized_path_info, :request_method, :path_info, :params, :mime_type, :headers, :authorization def initialize(request) super AppMap::Event.next_id_counter, :call, Thread.current.object_id self.request_method = request.request_method self.normalized_path_info = normalized_path(request) self.mime_type = request.headers['Content-Type'] - self.headers = RequestHandler.selected_headers(request.env) + self.headers = AppMap::Util.select_headers(request.env) self.authorization = request.headers['Authorization'] self.path_info = request.path_info.split('?')[0] # ActionDispatch::Http::ParameterFilter is deprecated parameter_filter_cls = \ if defined?(ActiveSupport::ParameterFilter) @@ -57,20 +37,22 @@ normalized_path_info: normalized_path_info, authorization: authorization, headers: headers, }.compact - 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__, - }.tap do |message| - properties = object_properties(val) - message[:properties] = properties if properties + unless params.blank? + 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__, + }.tap do |message| + properties = object_properties(val) + message[:properties] = properties if properties + end end end end end @@ -95,16 +77,16 @@ self.status = response.status self.mime_type = response.headers['Content-Type'] self.parent_id = parent_id self.elapsed = elapsed - self.headers = RequestHandler.selected_headers(response.headers) + self.headers = AppMap::Util.select_headers(response.headers) end def to_h super.tap do |h| h[:http_server_response] = { - status: status, + status_code: status, mime_type: mime_type, headers: headers }.compact end end