final class CorsMiddleware implements MiddlewareInterface (View source)

Applies the resolved CORS policy and terminates valid preflight requests.

Methods

__construct(CorsConfig $config, ResponseFactoryInterface $responseFactory)

Connects the immutable CORS policy with blank-response creation.

ResponseInterface
process(ServerRequestInterface $request, RequestHandlerInterface $handler)

Delegates ordinary requests and adds CORS headers only for configured allowed origins.

ResponseInterface

Details

__construct

__construct(CorsConfig $config, ResponseFactoryInterface $responseFactory)

Connects the immutable CORS policy with blank-response creation.

Parameters

CorsConfig $config
ResponseFactoryInterface $responseFactory

process

ResponseInterface process(ServerRequestInterface $request, RequestHandlerInterface $handler)

Delegates ordinary requests and adds CORS headers only for configured allowed origins.

Parameters

ServerRequestInterface $request
RequestHandlerInterface $handler

Return Value

ResponseInterface

Exceptions

InvalidArgumentException