Module: Datadog::AppSec::Contrib::Sinatra::DispatchPatch

Defined in:
lib/datadog/appsec/contrib/sinatra/patcher.rb

Overview

Hook into Base#dispatch!, which encompasses route filters

Instance Method Summary collapse

Instance Method Details

#dispatch!Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/datadog/appsec/contrib/sinatra/patcher.rb', line 51

def dispatch!
  env = @request.env

  context = env['datadog.waf.context']

  return super unless context

  # TODO: handle exceptions, except for super

  gateway_request = Gateway::Request.new(env)

  request_return, request_response = Instrumentation.gateway.push('sinatra.request.dispatch', gateway_request) do
    # handle process_route interruption
    catch(Ext::ROUTE_INTERRUPT) { super }
  end

  if request_response && request_response.any? { |action, _event| action == :block }
    self.response = AppSec::Response.negotiate(env).to_sinatra_response
    request_return = nil
  end

  request_return
end