Sha256: 41f60df37e4571357650b258d663c3e0cd34d71d7b410c1e417f116349cf15f1

Contents?: true

Size: 1.73 KB

Versions: 4

Compression:

Stored size: 1.73 KB

Contents

module Timber
  module Events
    # The HTTP request event tracks incoming HTTP requests.
    #
    # @note This event should be installed automatically through probes,
    #   such as the {Probes::ActionControllerLogSubscriber} probe.
    class HTTPServerRequest < Timber::Event
      attr_reader :host, :method, :path, :port, :query_string, :content_type,
        :remote_addr, :referrer, :request_id, :scheme, :user_agent

      def initialize(attributes)
        @host = attributes[:host] || raise(ArgumentError.new(":host is required"))
        @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]
        @scheme = attributes[:scheme] || raise(ArgumentError.new(":scheme is required"))
        @user_agent = attributes[:user_agent]
      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}}
      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]
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
timber-1.1.14 lib/timber/events/http_server_request.rb
timber-1.1.13 lib/timber/events/http_server_request.rb
timber-1.1.12 lib/timber/events/http_server_request.rb
timber-1.1.11 lib/timber/events/http_server_request.rb