class Middleware
The middleware interface provides a convenient wrapper for implementing HTTP middleware.
A middleware instance generally needs to respond to two methods:
call(request)
->response
close()
The call method is called for each request. The close method is called when the server is shutting down.
You do not need to use the Middleware class to implement middleware. You can implement the interface directly.
Nested
Definitions
def self.build(&block)
Build a middleware application using the given block.
Implementation
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)
Convert a block to a middleware delegate.
Signature
-
parameter
block
Proc
The block to convert to a middleware delegate.
-
returns
Middleware
The middleware delegate.
Implementation
def self.for(&block)
# Add a close method to the block.
def block.close
end
return self.new(block)
end
def initialize(delegate)
Initialize the middleware with the given delegate.
Signature
-
parameter
delegate
Object
The delegate object. A delegate is used for passing along requests that are not handled by this middleware.
Implementation
def initialize(delegate)
@delegate = delegate
end
attr :delegate
Signature
-
attribute
Object
The delegate object that is used for passing along requests that are not handled by this middleware.
def close
Close the middleware. Invokes the close method on the delegate.
Implementation
def close
@delegate.close
end
def call(request)
Call the middleware with the given request. Invokes the call method on the delegate.
Implementation
def call(request)
@delegate.call(request)
end