The BabDev\WebSocket\Server\Http\Middleware\RestrictToAllowedOrigins class is a server middleware which can be used to reject connections based on the Origin header from the HTTP request.
The allowed origin list can be updated at any time, including while the server is running.
To allow a origin, you can use the middleware's allowOrigin() method:
<?php declare(strict_types=1);
use BabDev\WebSocket\Server\Http\Middleware\RestrictToAllowedOrigins;
$middleware = new RestrictToAllowedOrigins($decoratedMiddleware);
$middleware->allowOrigin('babdev.com');
To allow a previously blocked IP address, you can use the middleware's removeAllowedOrigin() method:
<?php declare(strict_types=1);
use BabDev\WebSocket\Server\Http\Middleware\RestrictToAllowedOrigins;
$middleware = new RestrictToAllowedOrigins($decoratedMiddleware);
$middleware->allowOrigin('babdev.com');
$middleware->allowOrigin('github.com');
$middleware->removeAllowedOrigin('github.com');
It is recommended that this middleware is decorated by the BabDev\WebSocket\Server\Http\Middleware\ParseHttpRequest middleware in your application (see the message flow section from the architecture documentation to see the recommended stack with all optional middleware), however it can be placed anywhere after the HTTP request has been parsed and does not expect one of the server middleware sub-interfaces.
It is also recommended that this middleware decorates the BabDev\WebSocket\Server\WebSocket\Middleware\EstablishWebSocketConnection middleware, but it can decorate any server middleware.
How can I help you explore Laravel packages today?