Class: Airbrake::Rack::RequestBodyFilter

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

Overview

Note:

This filter is not used by default.

A filter that appends Rack request body to the notice.

Examples:

# Read and append up to 512 bytes from Rack request's body.
Airbrake.add_filter(Airbrake::Rack::RequestBodyFilter.new(512))

Since:

  • v5.7.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(length = 4096) ⇒ RequestBodyFilter

Returns a new instance of RequestBodyFilter.

Parameters:

  • length (Integer) (defaults to: 4096)

    The maximum number of bytes to read

Since:

  • v5.7.0



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

def initialize(length = 4096)
  @length = length
  @weight = 95
end

Instance Attribute Details

#weightInteger (readonly)

Returns:

  • (Integer)

Since:

  • v5.7.0



15
16
17
# File 'lib/airbrake/rack/request_body_filter.rb', line 15

def weight
  @weight
end

Instance Method Details

#call(notice) ⇒ Object

See Also:

  • FilterChain#refine

Since:

  • v5.7.0



24
25
26
27
28
29
30
# File 'lib/airbrake/rack/request_body_filter.rb', line 24

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

  notice[:environment][:body] = request.body.read(@length)
  request.body.rewind
end