Sha256: 50f6febed1515ac40fddabe889739ac2d6b9b2ce8f37ee9bb9437a6b6e12bdc5

Contents?: true

Size: 1.28 KB

Versions: 6

Compression:

Stored size: 1.28 KB

Contents

# Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
# frozen_string_literal: true

module Contrast
  module Agent
    # 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).
    class RequestHandler
      include Contrast::Components::Interface
      access_component :agent, :logging, :scope

      attr_reader :ruleset, :context

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

      def send_activity_messages
        Contrast::Utils::GemfileReader.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

      # If the response is streaming, we should only perform filtering on our stream safe rules
      def stream_safe_postfilter
        stream_safe_ruleset = ruleset.select(&:stream_safe?)
        postfilter_ruleset = Contrast::Agent::RuleSet.new(stream_safe_ruleset)
        postfilter_ruleset.postfilter
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
contrast-agent-3.16.0 lib/contrast/agent/request_handler.rb
contrast-agent-3.15.0 lib/contrast/agent/request_handler.rb
contrast-agent-3.14.0 lib/contrast/agent/request_handler.rb
contrast-agent-3.13.2 lib/contrast/agent/request_handler.rb
contrast-agent-3.13.1 lib/contrast/agent/request_handler.rb
contrast-agent-3.13.0 lib/contrast/agent/request_handler.rb