diff --git a/core/lib/Drupal/Core/StackMiddleware/ContentLength.php b/core/lib/Drupal/Core/StackMiddleware/ContentLength.php index 6f3172b810a9e5f89ea75d38733d0edbcb64a6a1..035d31e02c3ed9fc581a42434f67a0f4e0d21200 100644 --- a/core/lib/Drupal/Core/StackMiddleware/ContentLength.php +++ b/core/lib/Drupal/Core/StackMiddleware/ContentLength.php @@ -3,6 +3,7 @@ namespace Drupal\Core\StackMiddleware; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\BinaryFileResponse; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\HttpKernelInterface; @@ -26,6 +27,11 @@ public function __construct( */ public function handle(Request $request, $type = self::MAIN_REQUEST, $catch = TRUE): Response { $response = $this->httpKernel->handle($request, $type, $catch); + // Don't set a content-length header for files because they may be gzipped + // by the server. + if ($response instanceof BinaryFileResponse) { + return $response; + } if ($response->isInformational() || $response->isEmpty()) { return $response; }