class Rack::Builder
def use(middleware, *args, &block)
The +call+ method in this example sets an additional environment key which then can be
All requests through to this application will first be processed by the middleware class.
run lambda { |env| [200, { "content-type" => "text/plain" }, ["OK"]] }
use Middleware
end
end
@app.call(env)
env["rack.some_header"] = "setting an example"
def call(env)
end
@app = app
def initialize(app)
class Middleware
Specifies middleware to use in a stack.
def use(middleware, *args, &block) if @map mapping, @map = @map, nil @use << proc { |app| generate_map(app, mapping) } end @use << proc { |app| middleware.new(app, *args, &block) } end