Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. ContentLength.php

class ContentLength

Same name in this branch
  1. 11.1.x core/modules/big_pipe/src/StackMiddleware/ContentLength.php \Drupal\big_pipe\StackMiddleware\ContentLength

Adds a Content-Length HTTP header to responses.

Hierarchy

  • class \Drupal\Core\StackMiddleware\ContentLength implements \Symfony\Component\HttpKernel\HttpKernelInterface

Expanded class hierarchy of ContentLength

File

core/lib/Drupal/Core/StackMiddleware/ContentLength.php, line 12

Namespace

Drupal\Core\StackMiddleware
View source
class ContentLength implements HttpKernelInterface {
    
    /**
     * Constructs a new ContentLength instance.
     *
     * @param \Symfony\Component\HttpKernel\HttpKernelInterface $httpKernel
     *   The wrapped HTTP kernel.
     */
    public function __construct(HttpKernelInterface $httpKernel) {
    }
    
    /**
     * {@inheritdoc}
     */
    public function handle(Request $request, $type = self::MAIN_REQUEST, $catch = TRUE) : Response {
        $response = $this->httpKernel
            ->handle($request, $type, $catch);
        if ($response->isInformational() || $response->isEmpty()) {
            return $response;
        }
        if ($response->headers
            ->has('Transfer-Encoding')) {
            return $response;
        }
        // Drupal cannot set the correct content length header when there is a
        // server error.
        if ($response->isServerError()) {
            return $response;
        }
        $content = $response->getContent();
        if ($content === FALSE) {
            return $response;
        }
        $response->headers
            ->set('Content-Length', strlen($content), TRUE);
        return $response;
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
ContentLength::handle public function Handles a Request to convert it to a Response. Overrides HttpKernelInterface::handle
ContentLength::__construct public function Constructs a new ContentLength instance.
HttpKernelInterface::MAIN_REQUEST public constant
HttpKernelInterface::SUB_REQUEST public constant

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal