class Rollbar::UserInformer::Middleware
Public Class Methods
new(app)
click to toggle source
# File lib/rollbar/user_informer.rb, line 16 def initialize(app) @app = app end
Public Instance Methods
call(env)
click to toggle source
# File lib/rollbar/user_informer.rb, line 20 def call(env) status, headers, body = @app.call(env) if (replacement = Rollbar::UserInformer.user_information) && (error_uuid = env[REQUEST_ENV_KEY]) replacement = replacement.gsub(/\{\{\s*error_uuid\s*\}\}/, error_uuid) body = replace_placeholder(replacement, body, headers) headers["Error-Id"] = error_uuid end [status, headers, body] end
Private Instance Methods
replace_placeholder(replacement, body, headers)
click to toggle source
-
body interface is .each so we cannot use anything else
-
always call .close on the old body so it can get garbage collected if it is a File
# File lib/rollbar/user_informer.rb, line 34 def replace_placeholder(replacement, body, headers) new_body = [] body.each do |chunk| new_body << chunk.gsub(Rollbar::UserInformer.user_information_placeholder || DEFAULT_PLACEHOLDER, replacement) end headers["Content-Length"] = new_body.inject(0) { |sum, x| sum + x.bytesize }.to_s new_body ensure body.close if body&.respond_to?(:close) end