diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index a05abea..e46368c 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -867,9 +867,26 @@ function drupal_page_header() { * response is sent. */ function drupal_serve_page_from_cache(Response $response, Request $request) { + // Only allow caching in the browser and prevent that the response is stored + // by an external proxy server when the following conditions apply: + // 1. There is a session cookie on the request. + // 2. The Vary: Cookie header is on the response. + // 3. The Cache-Control header does not contain the no-cache directive. + if ($request->cookies->has(session_name()) && + in_array('Cookie', $response->getVary()) && + !$response->headers->hasCacheControlDirective('no-cache')) { + + $response->setPrivate(); + } + // Negotiate whether to use compression. if ($response->headers->get('Content-Encoding') == 'gzip' && extension_loaded('zlib')) { - if (strpos($request->headers->get('Accept-Encoding'), 'gzip') === FALSE) { + if (strpos($request->headers->get('Accept-Encoding'), 'gzip') !== FALSE) { + // The response content is already gzip'ed, so make sure + // zlib.output_compression does not compress it once more. + ini_set('zlib.output_compression', '0'); + } + else { // The client does not support compression. Decompress the content and // remove the Content-Encoding header. $content = $response->getContent(); @@ -877,23 +894,6 @@ function drupal_serve_page_from_cache(Response $response, Request $request) { $response->setContent($content); $response->headers->remove('Content-Encoding'); } - else { - // The response content is already gzip'ed, so make sure - // zlib.output_compression does not compress it once more. - ini_set('zlib.output_compression', '0'); - } - } - - // Prevent that the response is cached by an external proxy server and only - // allow it to be cached by the browser when the following conditions are met: - // 1. There is a session cookie on the request. - // 2. The Vary: Cookie header is on the response. - // 3. The Cache-Control header does not contain the no-cache directive. - if ($request->cookies->has(session_name()) && - in_array('Cookie', $response->getVary()) && - !$response->headers->hasCacheControlDirective('no-cache')) { - - $response->setPrivate(); } // Perform HTTP revalidation.