class Protocol::HTTP::Middleware
You do not need to use the Middleware class to implement middleware. You can implement the interface directly.
The call method is called for each request. The close method is called when the server is shutting down.
- ‘close()`
- `call(request)` -> `response`
A middleware instance generally needs to respond to two methods:
The middleware interface provides a convenient wrapper for implementing HTTP middleware.
def self.build(&block)
def self.build(&block) builder = Builder.new if block_given? if block.arity == 0 builder.instance_exec(&block) else yield builder end end return builder.to_app end
def self.for(&block)
def self.for(&block) def block.close end return self.new(block) end
def call(request)
def call(request) @delegate.call(request) end
def close
def close @delegate.close end
def initialize(delegate)
def initialize(delegate) @delegate = delegate end