class SmokeDetector::JavaScriptMonitors
Constants
- ACCEPTABLE_CONTENT
- TARGET_TAG
Public Class Methods
new(app)
click to toggle source
# File lib/smoke_detector/middleware/javascript_monitors.rb, line 7 def initialize(app) @app = app end
Public Instance Methods
call(env)
click to toggle source
# File lib/smoke_detector/middleware/javascript_monitors.rb, line 11 def call(env) status, headers, response = @app.call(env) if monitor?(headers) body = '' response.each { |part| body << part } if index = body.rindex(TARGET_TAG) body.insert(index + TARGET_TAG.length + 1, monitoring_code) headers["Content-Length"] = body.length.to_s response = [body] end end [status, headers, response] end
Private Instance Methods
monitor?(headers)
click to toggle source
# File lib/smoke_detector/middleware/javascript_monitors.rb, line 33 def monitor?(headers) headers["Content-Type"] =~ ACCEPTABLE_CONTENT && monitoring_code.present? end
monitoring_code()
click to toggle source
# File lib/smoke_detector/middleware/javascript_monitors.rb, line 29 def monitoring_code @monitoring_code ||= SmokeDetector.providers.map(&:client_monitoring_code).join('') end