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

Breadcrumb

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

function ContentLength::handle

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

Overrides HttpKernelInterface::handle

File

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

Class

ContentLength
Adds a Content-Length HTTP header to responses.

Namespace

Drupal\Core\StackMiddleware

Code

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;
}

API Navigation

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