lib/timber/events/http_server_request.rb in timber-1.1.14 vs lib/timber/events/http_server_request.rb in timber-2.0.0
- old
+ new
@@ -1,48 +1,40 @@
module Timber
module Events
- # The HTTP request event tracks incoming HTTP requests.
+ # The HTTP server request event tracks incoming HTTP requests to your HTTP server.
+ # Such as unicorn, webrick, puma, etc.
#
- # @note This event should be installed automatically through probes,
- # such as the {Probes::ActionControllerLogSubscriber} probe.
+ # @note This event should be installed automatically through integrations,
+ # such as the {Integrations::ActionController::LogSubscriber} integration.
class HTTPServerRequest < Timber::Event
- attr_reader :host, :method, :path, :port, :query_string, :content_type,
- :remote_addr, :referrer, :request_id, :scheme, :user_agent
+ attr_reader :body, :headers, :host, :method, :path, :port, :query_string, :request_id,
+ :scheme
def initialize(attributes)
+ @headers = Util::HTTPEvent.normalize_headers(attributes[:headers])
@host = attributes[:host] || raise(ArgumentError.new(":host is required"))
- @method = attributes[:method] || raise(ArgumentError.new(":method is required"))
+ @method = Util::HTTPEvent.normalize_method(attributes[:method]) || raise(ArgumentError.new(":method is required"))
@path = attributes[:path] || raise(ArgumentError.new(":path is required"))
@port = attributes[:port]
- @query_string = attributes[:query_string]
- @content_type = attributes[:content_type]
- @remote_addr = attributes[:remote_addr]
- @referrer = attributes[:referrer]
- @request_id = attributes[:request_id]
+ @query_string = Util::HTTPEvent.normalize_query_string(attributes[:query_string])
@scheme = attributes[:scheme] || raise(ArgumentError.new(":scheme is required"))
- @user_agent = attributes[:user_agent]
+ @request_id = attributes[:request_id]
+
+ @body = Util::HTTPEvent.normalize_body(@headers["content-type"], attributes[:body])
end
def to_hash
- {host: host, method: method, path: path, port: port, query_string: query_string,
- headers: {content_type: content_type, remote_addr: remote_addr, referrer: referrer,
- request_id: request_id, scheme: scheme, user_agent: user_agent}}
+ {body: body, headers: headers, host: host, method: method, path: path, port: port,
+ query_string: query_string, request_id: request_id, scheme: scheme}
end
alias to_h to_hash
def as_json(_options = {})
{:server_side_app => {:http_server_request => to_hash}}
end
def message
- 'Started %s "%s" for %s' % [
- method,
- path,
- remote_addr]
- end
-
- def status_description
- Rack::Utils::HTTP_STATUS_CODES[status]
+ 'Started %s "%s"' % [method, path]
end
end
end
end
\ No newline at end of file