function AlterContentMiddleware::handle

Same name in other branches
  1. 10 core/modules/system/tests/modules/http_middleware_test/src/StackMiddleware/AlterContentMiddleware.php \Drupal\http_middleware_test\StackMiddleware\AlterContentMiddleware::handle()

File

core/modules/system/tests/modules/http_middleware_test/src/StackMiddleware/AlterContentMiddleware.php, line 23

Class

AlterContentMiddleware
Alters the response before content length is calculated.

Namespace

Drupal\http_middleware_test\StackMiddleware

Code

public function handle(Request $request, int $type = self::MAIN_REQUEST, bool $catch = TRUE) : Response {
    $response = $this->httpKernel
        ->handle($request, $type, $catch);
    if (\Drupal::getContainer()->hasParameter('no-alter-content-length') && \Drupal::getContainer()->getParameter('no-alter-content-length')) {
        $response->setContent('<html><body><p>Avocados</p></body></html>');
    }
    return $response;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.