Content Length Middleware

The Content Length Middleware will automatically append a Content-Length header to the response. This is to replace the addContentLengthHeader setting that was removed from Slim 3. This middleware should be placed on the center of the middleware stack so it gets executed last.

Usage

  1. <?php
  2. use Slim\Factory\AppFactory;
  3. use Slim\Middleware\ContentLengthMiddleware;
  4. require __DIR__ . '/../vendor/autoload.php';
  5. $app = AppFactory::create();
  6. $contentLengthMiddleware = new ContentLengthMiddleware();
  7. $app->add($contentLengthMiddleware);
  8. // ...
  9. $app->run();