Final Class Yiisoft\HttpMiddleware\ContentLengthMiddleware
| Inheritance | Yiisoft\HttpMiddleware\ContentLengthMiddleware |
|---|---|
| Implements | Psr\Http\Server\MiddlewareInterface |
Configurable middleware that adds or removes the Content-Length header from the response.
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | Yiisoft\HttpMiddleware\ContentLengthMiddleware | |
| process() | Yiisoft\HttpMiddleware\ContentLengthMiddleware |
Method Details
| public mixed __construct ( boolean $removeOnTransferEncoding = true, boolean $add = true, array $doNotAddOnStatusCode = [ 100, // Continue 101, // Switching Protocols 102, // Processing 204, // No Content 205, // Reset Content 304, ] ) | ||
| $removeOnTransferEncoding | boolean |
Whether to remove the |
| $add | boolean |
Whether to add the |
| $doNotAddOnStatusCode | array |
List of HTTP status codes where |
public function __construct(
private readonly bool $removeOnTransferEncoding = true,
private readonly bool $add = true,
private readonly array $doNotAddOnStatusCode = [
100, // Continue
101, // Switching Protocols
102, // Processing
204, // No Content
205, // Reset Content
304, // Not Modified
],
) {
}
| 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 ($this->shouldRemoveContentLength($response)) {
return $response->withoutHeader('Content-Length');
}
if ($this->shouldSkipContentLength($response)) {
return $response;
}
return $this->addContentLength($response);
}
Signup or Login in order to comment.