Class: Airbrake::Rack::HttpHeadersFilter

Inherits:
Object
  • Object
show all
Defined in:
lib/airbrake/rack/http_headers_filter.rb

Overview

Adds HTTP request parameters.

Since:

  • v5.7.0

Constant Summary collapse

HTTP_HEADER_PREFIXES =

Returns the prefixes of the majority of HTTP headers in Rack (some prefixes match the header names for simplicity).

Returns:

  • (Array<String>)

    the prefixes of the majority of HTTP headers in Rack (some prefixes match the header names for simplicity)

Since:

  • v5.7.0

%w[
  HTTP_
  CONTENT_TYPE
  CONTENT_LENGTH
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeHttpHeadersFilter

Returns a new instance of HttpHeadersFilter.

Since:

  • v5.7.0



20
21
22
# File 'lib/airbrake/rack/http_headers_filter.rb', line 20

def initialize
  @weight = 98
end

Instance Attribute Details

#weightInteger (readonly)

Returns:

  • (Integer)

Since:

  • v5.7.0



18
19
20
# File 'lib/airbrake/rack/http_headers_filter.rb', line 18

def weight
  @weight
end

Instance Method Details

#call(notice) ⇒ Object

See Also:

  • FilterChain#refine

Since:

  • v5.7.0



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/airbrake/rack/http_headers_filter.rb', line 25

def call(notice)
  return unless (request = notice.stash[:rack_request])

  http_headers = request.env.map.with_object({}) do |(key, value), headers|
    if HTTP_HEADER_PREFIXES.any? { |prefix| key.to_s.start_with?(prefix) }
      headers[key] = value
    end

    headers
  end

  notice[:context].merge!(
    httpMethod: request.request_method,
    referer: request.referer,
    headers: http_headers,
  )
end