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
+38-16Lines changed: 38 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -659,27 +659,49 @@ passed explicitly.
659
659
660
660
### Middleware
661
661
662
-
Middleware can be added to the server using [`MiddlewareRunner`](src/MiddlewareRunner.php)
663
-
instead of the `callable`. A middleware is expected to adhere the following rules:
662
+
As documented above, the [`StreamingServer`](#streamingserver) accepts a single
663
+
request handler argument that is responsible for processing an incoming
664
+
HTTP request and then creating and returning an outgoing HTTP response.
665
+
666
+
Many common use cases involve validating, processing, manipulating the incoming
667
+
HTTP request before passing it to the final business logic request handler.
668
+
As such, this project supports the concept of middleware request handlers.
669
+
670
+
A middleware request handler is expected to adhere the following rules:
664
671
665
672
* It is a `callable`.
666
673
* It accepts `ServerRequestInterface` as first argument and optional `callable` as second argument.
667
674
* It returns a `ResponseInterface` (or any promise which can be consumed by [`Promise\resolve`](http://reactphp.org/promise/#resolve) resolving to a `ResponseInterface`)
668
675
* It calls `$next($request)` to continue processing the next middleware function or returns explicitly to abort the chain
669
676
670
-
The following example adds a middleware that adds the current time to the request as a
671
-
header (`Request-Time`) and middleware that always returns a 200 code without a body:
677
+
Note that this very simple definition allows you to use either anonymous
678
+
functions or any classes that use the magic `__invoke()` method.
679
+
This allows you to easily create custom middleware request handlers on the fly
680
+
or use a class based approach to ease using existing middleware implementations.
681
+
682
+
While this project does provide the means to *use* middleware implementations,
683
+
it does not aim to *define* how middleware implementations should look like.
684
+
We realize that there's a vivid ecosystem of middleware implementations and
685
+
ongoing effort to standardize interfaces between these and support this goal.
686
+
As such, this project only bundles a few middleware implementations that are
687
+
required to match PHP's request behavior (see below) and otherwise actively
0 commit comments