0 follower

Final Class Yiisoft\HttpMiddleware\HeadRequestMiddleware

InheritanceYiisoft\HttpMiddleware\HeadRequestMiddleware
ImplementsPsr\Http\Server\MiddlewareInterface

Middleware removes the body from response for HEAD requests.

Method Details

Hide inherited methods

__construct() public method

public mixed __construct ( \Psr\Http\Message\StreamFactoryInterface $streamFactory )
$streamFactory \Psr\Http\Message\StreamFactoryInterface

Factory to create a stream.

                public function __construct(
    private readonly StreamFactoryInterface $streamFactory,
) {
}

            
process() public method

public \Psr\Http\Message\ResponseInterface process ( \Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Server\RequestHandlerInterface $handler )
$request \Psr\Http\Message\ServerRequestInterface
$handler \Psr\Http\Server\RequestHandlerInterface

                public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
    $response = $handler->handle($request);
    if ($request->getMethod() !== 'HEAD') {
        return $response;
    }
    return $response->withBody(
        $this->streamFactory->createStream(),
    );
}