内容长度中间件

内容长度中间件将自动向响应追加 Content-Length 头文件。这是为了替换从 Slim 3 中删除的 addContentLengthHeader 设置。此中间件应置于中间件堆栈的末尾,以便它首先被执行然后最后退出。

用法

<?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();