Class: TCellAgent::Instrumentation::Rails::TCellBodyProxy
- Inherits:
-
Object
- Object
- TCellAgent::Instrumentation::Rails::TCellBodyProxy
show all
- Defined in:
- lib/tcell_agent/rails/tcell_body_proxy.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(body, js_agent_insertion_proc, script_insert, response_headers) ⇒ TCellBodyProxy
Returns a new instance of TCellBodyProxy.
9
10
11
12
13
14
15
16
17
18
|
# File 'lib/tcell_agent/rails/tcell_body_proxy.rb', line 9
def initialize(body,
js_agent_insertion_proc,
script_insert,
)
@content_length = 0
@body = body
@js_agent_insertion_proc = js_agent_insertion_proc
@script_insert = script_insert
@response_headers =
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
46
47
48
|
# File 'lib/tcell_agent/rails/tcell_body_proxy.rb', line 46
def method_missing(method_name, *args, &block)
@body.__send__(method_name, *args, &block)
end
|
Instance Attribute Details
#content_length ⇒ Object
Returns the value of attribute content_length.
7
8
9
|
# File 'lib/tcell_agent/rails/tcell_body_proxy.rb', line 7
def content_length
@content_length
end
|
Returns the value of attribute meta_data.
7
8
9
|
# File 'lib/tcell_agent/rails/tcell_body_proxy.rb', line 7
def meta_data
@meta_data
end
|
Instance Method Details
#close ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/tcell_agent/rails/tcell_body_proxy.rb', line 20
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 ⇒ Object
32
33
34
35
36
37
38
39
40
|
# File 'lib/tcell_agent/rails/tcell_body_proxy.rb', line 32
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
|
#process_body(body) ⇒ Object
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/tcell_agent/rails/tcell_body_proxy.rb', line 50
def process_body(body)
new_body = body
TCellAgent::Instrumentation.safe_block('Processing tcell body proxy body') do
chunked_response_match = nil
if @response_headers['Transfer-Encoding'] == 'chunked' &&
body.class.name == 'String' &&
body =~ /^([[:xdigit:]]+)(;.+)?\r\n/
chunked_response_match = Regexp.last_match(1)
@content_length += chunked_response_match.to_i(16)
end
if body.class.name == 'ActionView::OutputBuffer' ||
(body.class.name == 'String' && !chunked_response_match)
if @js_agent_insertion_proc
new_body = @js_agent_insertion_proc.call(@script_insert, body)
if new_body != body
@js_agent_insertion_proc = nil
end
end
@content_length += new_body.bytesize
end
end
new_body
end
|
#respond_to?(method_name, include_all = false) ⇒ Boolean
42
43
44
|
# File 'lib/tcell_agent/rails/tcell_body_proxy.rb', line 42
def respond_to?(method_name, include_all = false)
@body.respond_to?(method_name, include_all)
end
|