Class: Datadog::AppSec::Contrib::Rails::Gateway::Request

Inherits:
Instrumentation::Gateway::Argument show all
Defined in:
lib/datadog/appsec/contrib/rails/gateway/request.rb

Overview

Gateway Request argument. Normalized extration of data from ActionDispatch::Request

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request) ⇒ Request

Returns a new instance of Request.



14
15
16
17
# File 'lib/datadog/appsec/contrib/rails/gateway/request.rb', line 14

def initialize(request)
  super()
  @request = request
end

Instance Attribute Details

#requestObject (readonly)

Returns the value of attribute request.



12
13
14
# File 'lib/datadog/appsec/contrib/rails/gateway/request.rb', line 12

def request
  @request
end

Instance Method Details

#envObject



19
20
21
# File 'lib/datadog/appsec/contrib/rails/gateway/request.rb', line 19

def env
  request.env
end

#headersObject



23
24
25
# File 'lib/datadog/appsec/contrib/rails/gateway/request.rb', line 23

def headers
  request.headers
end

#hostObject



27
28
29
# File 'lib/datadog/appsec/contrib/rails/gateway/request.rb', line 27

def host
  request.host
end

#parsed_bodyObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/datadog/appsec/contrib/rails/gateway/request.rb', line 39

def parsed_body
  # force body parameter parsing, which is done lazily by Rails
  request.parameters

  # usually Hash<String,String> but can be a more complex
  # Hash<String,String||Array||Hash> when e.g coming from JSON or
  # with Rails advanced param square bracket parsing
  body = request.env['action_dispatch.request.request_parameters']

  return if body.nil?

  body.reject do |k, _v|
    request.env['action_dispatch.request.path_parameters'].key?(k)
  end
end

#remote_addrObject



35
36
37
# File 'lib/datadog/appsec/contrib/rails/gateway/request.rb', line 35

def remote_addr
  request.remote_addr
end

#route_paramsObject



55
56
57
58
59
60
61
# File 'lib/datadog/appsec/contrib/rails/gateway/request.rb', line 55

def route_params
  excluded = [:controller, :action]

  request.env['action_dispatch.request.path_parameters'].reject do |k, _v|
    excluded.include?(k)
  end
end

#user_agentObject



31
32
33
# File 'lib/datadog/appsec/contrib/rails/gateway/request.rb', line 31

def user_agent
  request.user_agent
end