Class: Sentry::RequestInterface

Inherits:
Interface show all
Defined in:
lib/sentry/interfaces/request.rb

Constant Summary collapse

REQUEST_ID_HEADERS =
%w(action_dispatch.request_id HTTP_X_REQUEST_ID).freeze
CONTENT_HEADERS =
%w(CONTENT_TYPE CONTENT_LENGTH).freeze
IP_HEADERS =
[
  "REMOTE_ADDR",
  "HTTP_CLIENT_IP",
  "HTTP_X_REAL_IP",
  "HTTP_X_FORWARDED_FOR"
].freeze
MAX_BODY_LIMIT =
4096 * 4

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Interface

inherited, registered, #to_hash

Constructor Details

#initialize(req) ⇒ RequestInterface

Returns a new instance of RequestInterface.



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/sentry/interfaces/request.rb', line 37

def initialize(req)
  env = req.env

  if Sentry.configuration.send_default_pii
    self.data = read_data_from(req)
    self.cookies = req.cookies
  end

  self.url = req.scheme && req.url.split('?').first
  self.method = req.request_method
  self.query_string = req.query_string

  self.headers = filter_and_format_headers(env)
  self.env     = filter_and_format_env(env)
end

Instance Attribute Details

#cookiesObject

Returns the value of attribute cookies.



18
19
20
# File 'lib/sentry/interfaces/request.rb', line 18

def cookies
  @cookies
end

#dataObject

Returns the value of attribute data.



18
19
20
# File 'lib/sentry/interfaces/request.rb', line 18

def data
  @data
end

#envObject

Returns the value of attribute env.



18
19
20
# File 'lib/sentry/interfaces/request.rb', line 18

def env
  @env
end

#headersObject

Returns the value of attribute headers.



18
19
20
# File 'lib/sentry/interfaces/request.rb', line 18

def headers
  @headers
end

#methodObject

Returns the value of attribute method.



18
19
20
# File 'lib/sentry/interfaces/request.rb', line 18

def method
  @method
end

#query_stringObject

Returns the value of attribute query_string.



18
19
20
# File 'lib/sentry/interfaces/request.rb', line 18

def query_string
  @query_string
end

#urlObject

Returns the value of attribute url.



18
19
20
# File 'lib/sentry/interfaces/request.rb', line 18

def url
  @url
end

Class Method Details

.clean_env(env) ⇒ Object



26
27
28
29
30
31
32
33
34
35
# File 'lib/sentry/interfaces/request.rb', line 26

def self.clean_env(env)
  unless Sentry.configuration.send_default_pii
    # need to completely wipe out ip addresses
    RequestInterface::IP_HEADERS.each do |header|
      env.delete(header)
    end
  end

  env
end

.from_rack(env) ⇒ Object



20
21
22
23
24
# File 'lib/sentry/interfaces/request.rb', line 20

def self.from_rack(env)
  env = clean_env(env)
  req = ::Rack::Request.new(env)
  self.new(req)
end