class AdminIt::Middleware

AdminIt middleware

Constants

SUBST_REGEXP

Public Class Methods

new(app) click to toggle source
# File lib/admin_it/middleware.rb, line 38
def initialize(app)
  @app = app
end

Public Instance Methods

call(env) click to toggle source
# File lib/admin_it/middleware.rb, line 42
def call(env)
  request = env[Request::ENV_KEY] = Request.new(env)
  status, headers, body = @app.call(env)
  if request.process?
    length = 0
    body.each do |str|
      str.gsub!(SUBST_REGEXP) { |s| request[SUBST_REGEXP.match(s)[1]] }
      length += str.bytesize
    end
    headers['Content-Length'] = length.to_s
  end
  [status, headers, body]
end