AlterContentMiddleware.php

Same filename in other branches
  1. 11.x core/modules/system/tests/modules/http_middleware_test/src/StackMiddleware/AlterContentMiddleware.php

Namespace

Drupal\http_middleware_test\StackMiddleware

File

core/modules/system/tests/modules/http_middleware_test/src/StackMiddleware/AlterContentMiddleware.php

View source
<?php

declare (strict_types=1);
namespace Drupal\http_middleware_test\StackMiddleware;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\HttpKernelInterface;

/**
 * Alters the response before content length is calculated.
 */
final class AlterContentMiddleware implements HttpKernelInterface {
    public function __construct(HttpKernelInterface $httpKernel) {
    }
    
    /**
     * {@inheritdoc}
     */
    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;
    }

}

Classes

Title Deprecated Summary
AlterContentMiddleware Alters the response before content length is calculated.

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