内容长度中间件

内容长度中间件会自动将Content-Length标头附加到响应中。这是为了替换addContentLengthHeader从 Slim 3 中删除的设置。这个中间件应该放在中间件堆栈的末尾,以便它首先执行并最后退出。

用法

<?php
use Slim\Factory\AppFactory;
use Slim\Middleware\ContentLengthMiddleware;

require __DIR__ . '/../vendor/autoload.php';

$app = AppFactory::create();

// Add any middleware which may modify the response body before adding the ContentLengthMiddleware

$contentLengthMiddleware = new ContentLengthMiddleware();
$app->add($contentLengthMiddleware);

// ...

$app->run();