Class: Datadog::AppSec::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/datadog/appsec/response.rb

Overview

AppSec response

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status:, headers: {}, body: []) ⇒ Response

Returns a new instance of Response.



10
11
12
13
14
# File 'lib/datadog/appsec/response.rb', line 10

def initialize(status:, headers: {}, body: [])
  @status = status
  @headers = headers
  @body = body
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



8
9
10
# File 'lib/datadog/appsec/response.rb', line 8

def body
  @body
end

#headersObject (readonly)

Returns the value of attribute headers.



8
9
10
# File 'lib/datadog/appsec/response.rb', line 8

def headers
  @headers
end

#statusObject (readonly)

Returns the value of attribute status.



8
9
10
# File 'lib/datadog/appsec/response.rb', line 8

def status
  @status
end

Class Method Details

.negotiate(env) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/datadog/appsec/response.rb', line 29

def negotiate(env)
  Response.new(
    status: 403,
    headers: { 'Content-Type' => 'text/html' },
    body: [Datadog::AppSec::Assets.blocked(format: format(env))]
  )
end

Instance Method Details

#to_action_dispatch_responseObject



24
25
26
# File 'lib/datadog/appsec/response.rb', line 24

def to_action_dispatch_response
  ::ActionDispatch::Response.new(status, headers, body)
end

#to_rackObject



16
17
18
# File 'lib/datadog/appsec/response.rb', line 16

def to_rack
  [status, headers, body]
end

#to_sinatra_responseObject



20
21
22
# File 'lib/datadog/appsec/response.rb', line 20

def to_sinatra_response
  ::Sinatra::Response.new(body, status, headers)
end