Class: Protocol::HTTP::Middleware
- Defined in:
- lib/protocol/http/middleware.rb,
lib/protocol/http/middleware/builder.rb
Overview
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.
Direct Known Subclasses
Defined Under Namespace
Modules: HelloWorld, NotFound, Okay Classes: Builder
Constant Summary
Constants inherited from Methods
Protocol::HTTP::Methods::CONNECT, Protocol::HTTP::Methods::DELETE, Protocol::HTTP::Methods::GET, Protocol::HTTP::Methods::HEAD, Protocol::HTTP::Methods::OPTIONS, Protocol::HTTP::Methods::PATCH, Protocol::HTTP::Methods::POST, Protocol::HTTP::Methods::PUT, Protocol::HTTP::Methods::TRACE
Instance Attribute Summary collapse
-
#delegate ⇒ Object
readonly
Returns the value of attribute delegate.
Class Method Summary collapse
- .build(&block) ⇒ Object
-
.for(&block) ⇒ Object
Convert a block to a middleware delegate.
Instance Method Summary collapse
- #call(request) ⇒ Object
- #close ⇒ Object
-
#initialize(delegate) ⇒ Middleware
constructor
A new instance of Middleware.
Methods inherited from Methods
Constructor Details
#initialize(delegate) ⇒ Middleware
Returns a new instance of Middleware.
32 33 34 |
# File 'lib/protocol/http/middleware.rb', line 32 def initialize(delegate) @delegate = delegate end |
Instance Attribute Details
#delegate ⇒ Object (readonly)
Returns the value of attribute delegate.
36 37 38 |
# File 'lib/protocol/http/middleware.rb', line 36 def delegate @delegate end |
Class Method Details
.build(&block) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/protocol/http/middleware/builder.rb', line 30 def self.build(&block) builder = Builder.new builder.instance_eval(&block) return builder.to_app end |
.for(&block) ⇒ Object
Convert a block to a middleware delegate.
25 26 27 28 29 30 |
# File 'lib/protocol/http/middleware.rb', line 25 def self.for(&block) def block.close end return self.new(block) end |
Instance Method Details
#call(request) ⇒ Object
42 43 44 |
# File 'lib/protocol/http/middleware.rb', line 42 def call(request) @delegate.call(request) end |
#close ⇒ Object
38 39 40 |
# File 'lib/protocol/http/middleware.rb', line 38 def close @delegate.close end |