You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+74-4Lines changed: 74 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -798,10 +798,27 @@ As such, this project supports the concept of middleware request handlers.
798
798
799
799
A middleware request handler is expected to adhere the following rules:
800
800
801
-
* It is a `callable`.
802
-
* It accepts `ServerRequestInterface` as first argument and optional `callable` as second argument.
803
-
* It returns a `ResponseInterface` (or any promise which can be consumed by [`Promise\resolve`](http://reactphp.org/promise/#resolve) resolving to a `ResponseInterface`)
804
-
* It calls `$next($request)` to continue processing the next middleware function or returns explicitly to abort the chain
801
+
* It is a valid `callable`.
802
+
* It accepts `ServerRequestInterface` as first argument and an optional
803
+
`callable` as second argument.
804
+
* It returns either:
805
+
* An instance implementing `ResponseInterface` for direct consumption.
806
+
* Any promise which can be consumed by
807
+
[`Promise\resolve()`](http://reactphp.org/promise/#resolve) resolving to a
808
+
`ResponseInterface` for deferred consumption.
809
+
* It MAY throw an `Exception` (or return a rejected promise) in order to
810
+
signal an error condition and abort the chain.
811
+
* It calls `$next($request)` to continue processing the next middleware
812
+
request handler function or returns explicitly without calling `$next` to
813
+
abort the chain.
814
+
* The `$next` request handler function (recursively) invokes the next request
815
+
handler from the chain with the same logic as above and returns (or throws)
816
+
as above.
817
+
* The `$request` may be modified prior to calling `$next($request)` to
818
+
change the incoming request the next middleware operates on.
819
+
* The `$next` return value may be consumed to modify the outgoing response.
820
+
* The `$next` request handler MAY be called more than once if you want to
821
+
implement custom "retry" logic etc.
805
822
806
823
Note that this very simple definition allows you to use either anonymous
807
824
functions or any classes that use the magic `__invoke()` method.
0 commit comments