Skip to content

Encode the response body to gzip or deflate

Anatoly Nekhay edited this page Jan 7, 2019 · 1 revision

Install middleware

Learn more about the middleware

composer require middlewares/encoder

Encode all content

Open the public/index.php and add the following code before running the application:

$container->get(Sunrise\Http\Router\RouterInterface::class)
->addMiddleware(new Middlewares\GzipEncoder());

Encode route content only

/**
 * @Route(
 *   id="test",
 *   path="/test",
 *   methods={"GET"},
 *   before={
 *     "Middlewares\GzipEncoder"
 *   }
 * )
 */
class TestController implements MiddlewareInterface
{
    // some code
}