Class: Contrast::Agent::RequestHandler

Inherits:
Object
  • Object
show all
Includes:
Components::Interface
Defined in:
lib/contrast/agent/request_handler.rb

Overview

This class is instantiated when we receive a request and the agent is enabled to process that request. It holds the ruleset that we perform filtering operations on (currently prefilter and postfilter).

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Components::Interface

included

Constructor Details

#initialize(context) ⇒ RequestHandler

Returns a new instance of RequestHandler.



15
16
17
18
# File 'lib/contrast/agent/request_handler.rb', line 15

def initialize context
  @context = context
  @ruleset = AGENT.ruleset
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



13
14
15
# File 'lib/contrast/agent/request_handler.rb', line 13

def context
  @context
end

#rulesetObject (readonly)

Returns the value of attribute ruleset.



13
14
15
# File 'lib/contrast/agent/request_handler.rb', line 13

def ruleset
  @ruleset
end

Instance Method Details

#send_activity_messagesObject



20
21
22
23
24
25
# File 'lib/contrast/agent/request_handler.rb', line 20

def send_activity_messages
  Contrast::Agent::Inventory::DependencyUsageAnalysis.instance.generate_library_usage(context.activity)
  [context.server_activity, context.activity, context.observed_route].each do |message|
    Contrast::Agent.messaging_queue.send_event_eventually(message)
  end
end

#stream_safe_postfilterObject

If the response is streaming, we should only perform filtering on our stream safe rules



28
29
30
31
32
# File 'lib/contrast/agent/request_handler.rb', line 28

def stream_safe_postfilter
  stream_safe_ruleset = ruleset.select(&:stream_safe?)
  postfilter_ruleset = Contrast::Agent::RuleSet.new(stream_safe_ruleset)
  postfilter_ruleset.postfilter
end