class TCellAgent::Instrumentation::Rails::TCellBodyProxy

Attributes

content_length[RW]

for specs

meta_data[RW]

Public Class Methods

new(body, process_js_and_dlp, js_agent_insertion_proc, script_insert, dlp_cleaner_proc, tcell_context) click to toggle source
# File lib/tcell_agent/rails/tcell_body_proxy.rb, line 12
def initialize(body,
               process_js_and_dlp,
               js_agent_insertion_proc,
               script_insert,
               dlp_cleaner_proc,
               tcell_context)
  @content_length = 0
  @body = body

  @process_js_and_dlp = process_js_and_dlp

  @js_agent_insertion_proc = js_agent_insertion_proc
  @script_insert = script_insert

  @dlp_cleaner_proc = dlp_cleaner_proc
  @tcell_context = tcell_context
end

Public Instance Methods

close() click to toggle source
# File lib/tcell_agent/rails/tcell_body_proxy.rb, line 30
def close
  TCellAgent::Instrumentation.safe_block('Running AppSensor deferred due to streaming') do
    if @meta_data
      @meta_data.response_content_bytes_len = @content_length
      appfirewall_policy = TCellAgent.policy(TCellAgent::PolicyTypes::APPSENSOR)
      appfirewall_policy.check_appfirewall_injections(@meta_data)
    end
  end

  @body.close if @body.respond_to?(:close)
end
each() { |body_chunk| ... } click to toggle source
# File lib/tcell_agent/rails/tcell_body_proxy.rb, line 42
def each
  return to_enum(:each) unless block_given?

  @body.each do |body_chunk|
    body_chunk = process_body(body_chunk)

    yield body_chunk
  end
end
method_missing(method_name, *args, &block) click to toggle source
# File lib/tcell_agent/rails/tcell_body_proxy.rb, line 56
def method_missing(method_name, *args, &block)
  @body.__send__(method_name, *args, &block)
end
process_body(body) click to toggle source
# File lib/tcell_agent/rails/tcell_body_proxy.rb, line 60
def process_body(body)
  TCellAgent::Instrumentation.safe_block('Processing tcell body proxy body') do
    chunked_response_match = nil
    if body.class.name == 'String' && body =~ /^([[:xdigit:]]+)(;.+)?\r\n/
      chunked_response_match = Regexp.last_match(1)
      @content_length += chunked_response_match.to_i(16)
    end

    new_body = body
    if body.class.name == 'ActionView::OutputBuffer' ||
       (body.class.name == 'String' && !chunked_response_match)
      if @process_js_and_dlp
        if @js_agent_insertion_proc
          new_body = @js_agent_insertion_proc.call(@script_insert, body)
          if new_body != body
            # js agent was successfully inserted so no need to keep
            # calling this proc
            @js_agent_insertion_proc = nil
          end
        end
        if @dlp_cleaner_proc
          @dlp_cleaner_proc.call(@tcell_context, new_body)
        end
      end

      @content_length += new_body.bytesize
    end

    new_body
  end
end
respond_to?(method_name, include_all = false) click to toggle source
# File lib/tcell_agent/rails/tcell_body_proxy.rb, line 52
def respond_to?(method_name, include_all = false)
  @body.respond_to?(method_name, include_all)
end