Final Class Yiisoft\HttpMiddleware\HeadRequestMiddleware
| Inheritance | Yiisoft\HttpMiddleware\HeadRequestMiddleware |
|---|---|
| Implements | Psr\Http\Server\MiddlewareInterface |
Middleware removes the body from response for HEAD requests.
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | Yiisoft\HttpMiddleware\HeadRequestMiddleware | |
| process() | Yiisoft\HttpMiddleware\HeadRequestMiddleware |
Method Details
| 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,
) {
}
| 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(),
);
}
Signup or Login in order to comment.