#require 'rack/utils' module Bushido class Middleware include Rack::Utils def initialize(app, opts = {}) @app = app end def call(env) if Bushido::Platform.on_bushido? and Bushido::Bar.in_bar_display_path?(env) status, headers, response = @app.call(env) content = "" response.each { |part| content += part } # "claiming" bar + stats ? content.gsub!(/<\/body>/i, <<-STR STR ) headers['content-length'] = bytesize(content).to_s [status, headers, [content]] else @app.call(env) end end end end