0 follower

Final Class Yiisoft\HttpMiddleware\RemoveBodyMiddleware

InheritanceYiisoft\HttpMiddleware\RemoveBodyMiddleware
ImplementsPsr\Http\Server\MiddlewareInterface

Removes the body from the response for specific HTTP status codes.

Method Details

Hide inherited methods

__construct() public method

public mixed __construct ( \Psr\Http\Message\StreamFactoryInterface $streamFactory, array $statusCodes = [
    
100,
    
// Continue
    
101,
    
// Switching Protocols
    
102,
    
// Processing
    
204,
    
// No Content
    
205,
    
// Reset Content
    
304,
]
)
$streamFactory \Psr\Http\Message\StreamFactoryInterface

Factory to create a stream.

$statusCodes array

List of HTTP status codes for which the body should be removed.

                public function __construct(
    private readonly StreamFactoryInterface $streamFactory,
    private readonly array $statusCodes = [
        100, // Continue
        101, // Switching Protocols
        102, // Processing
        204, // No Content
        205, // Reset Content
        304, // Not Modified
    ],
) {
}

            
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);
    return $this->shouldRemoveBody($response)
        ? $this->removeBody($response)
        : $response;
}