for/http-middleware-psr15-adapter

PSR15 adapter for react/http middleware

Package info

github.com/friends-of-reactphp/http-middleware-psr15-adapter

pkg:composer/for/http-middleware-psr15-adapter

Statistics

Installs: 17 409

Dependents: 4

Suggesters: 0

Stars: 25

Open Issues: 0

v2.0.0 2022-08-14 21:05 UTC

Requires

Requires (Dev)

Suggests

None

Provides

None

Conflicts

None

Replaces

None

MIT 078431f1eff2235fcf6bf0fd55fc1425fdbf7eda

httphttpsmiddlewarereactphppsr15

This package is auto-updated.

Last update: 2026-06-15 17:48:32 UTC


README

👁 CI status

Wraps PSR-15 middleware using async and await from react/async utilizing fibers making them usable within react/http as middleware.

Install

To install via Composer, use the command below, it will automatically detect the latest version and bind it with ^.

composer require for/http-middleware-psr15-adapter

Usage

The following usage example uses middlewares/redirect adding one redirect, and using the callback to call several methods on the redirect middleware to change it's behavior:

$server = new Server(
 /** Other middleware */
 new PSR15Middleware(
 (new Redirect(['/old-url' => '/new-url']))->permanent(false)->query(false)->method(['GET', 'POST'])
 ),
 /** Other middleware */
);

Grouped Usage

When using more then one PSR-15 in a row the GroupedPSR15Middleware is more performing than using multiple PSR15Middleware. Consider the following example where we add middlewares/cache for expires headers:

$loop = Factory::create(); 
$server = new Server([
 /** Other middleware */
 (new GroupedPSR15Middleware($loop))->withMiddleware( 
 (new Redirect(['/old-url' => '/new-url']))->permanent(false)->query(false)->method(['GET', 'POST'])
 )->withMiddleware(
 new Expires()
 ),
 /** Other middleware */
]);