Skip to content
Snippets Groups Projects
Verified Commit 64e70104 authored by Théodore Biadala's avatar Théodore Biadala
Browse files

Issue #3454507 by hablat, catch: Aggregated asset generation causes uncacheable assets

(cherry picked from commit 4f37d8d6)
parent f27c142a
No related branches found
No related tags found
17 merge requests!10663Issue #3495778: Update phpdoc in FileSaveHtaccessLoggingTest,!10451Issue #3472458 by watergate, smustgrave: CKEditor 5 show blocks label is not translated,!103032838547 Fix punctuation rules for inline label suffix colon with CSS only,!10150Issue #3467294 by quietone, nod_, smustgrave, catch, longwave: Change string...,!10130Resolve #3480321 "Second level menu",!9936Issue #3483087: Check the module:// prefix in the translation server path and replace it with the actual module path,!9933Issue #3394728 by ankondrat4: Undefined array key "#prefix" and deprecated function: explode() in Drupal\file\Element\ManagedFile::uploadAjaxCallback(),!9914Issue #3451136 by quietone, gapple, ghost of drupal past: Improve...,!9882Draft: Issue #3481777 In bulk_form ensure the triggering element is the bulk_form button,!9839Issue #3445469 by pooja_sharma, smustgrave: Add additional test coverage for...,!9815Issue #3480025: There is no way to remove entity cache items,!9757Issue #3478869 Add "All" or overview links to parent links,!9752Issue #3439910 by pooja_sharma, vensires: Fix Toolbar tests that rely on UID1's super user behavior,!9749Issue #3439910 by pooja_sharma, vensires: Fix Toolbar tests that rely on UID1's super user behavior,!9678Issue #3465132 by catch, Spokje, nod_: Show test run time by class in run-tests.sh output,!9578Issue #3304746 by scott_euser, casey, smustgrave: BigPipe cannot handle (GET)...,!9449Issue #3344041: Allow textarea widgets to be used for text (formatted) fields
Pipeline #276138 canceled
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
use Drupal\Core\Theme\ThemeManagerInterface; use Drupal\Core\Theme\ThemeManagerInterface;
use Drupal\system\FileDownloadController; use Drupal\system\FileDownloadController;
use Symfony\Component\HttpFoundation\BinaryFileResponse; use Symfony\Component\HttpFoundation\BinaryFileResponse;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
...@@ -183,6 +184,11 @@ public function deliver(Request $request, string $file_name) { ...@@ -183,6 +184,11 @@ public function deliver(Request $request, string $file_name) {
$generated_hash = $this->generateHash($group); $generated_hash = $this->generateHash($group);
$data = $this->optimizer->optimizeGroup($group); $data = $this->optimizer->optimizeGroup($group);
$response = new Response($data, 200, [
'Cache-control' => static::CACHE_CONTROL,
'Content-Type' => $this->contentType,
]);
// However, the hash from the library definitions in code may not match the // However, the hash from the library definitions in code may not match the
// hash from the URL. This can be for three reasons: // hash from the URL. This can be for three reasons:
// 1. Someone has requested an outdated URL, i.e. from a cached page, which // 1. Someone has requested an outdated URL, i.e. from a cached page, which
...@@ -198,10 +204,15 @@ public function deliver(Request $request, string $file_name) { ...@@ -198,10 +204,15 @@ public function deliver(Request $request, string $file_name) {
if (hash_equals($generated_hash, $received_hash)) { if (hash_equals($generated_hash, $received_hash)) {
$this->dumper->dumpToUri($data, $this->assetType, $uri); $this->dumper->dumpToUri($data, $this->assetType, $uri);
} }
return new Response($data, 200, [ else {
'Cache-control' => static::CACHE_CONTROL, $expected_filename = $this->fileExtension . '_' . $generated_hash . '.' . $this->fileExtension;
'Content-Type' => $this->contentType, $response = new RedirectResponse(
]); str_replace($file_name, $expected_filename, $request->getRequestUri()),
301,
['Cache-Control' => 'public, max-age=3600, must-revalidate'],
);
}
return $response;
} }
/** /**
......
...@@ -187,16 +187,12 @@ protected function assertInvalidAggregates(string $url): void { ...@@ -187,16 +187,12 @@ protected function assertInvalidAggregates(string $url): void {
$session->visit($this->setInvalidLibrary($url)); $session->visit($this->setInvalidLibrary($url));
$this->assertSession()->statusCodeEquals(200); $this->assertSession()->statusCodeEquals(200);
// When an invalid asset hash name is given.
$session->visit($this->replaceGroupHash($url)); $session->visit($this->replaceGroupHash($url));
$this->assertSession()->statusCodeEquals(200); $this->assertSession()->statusCodeEquals(200);
$headers = $session->getResponseHeaders(); $current_url = $session->getCurrentUrl();
$this->assertEquals(['no-store, private'], $headers['Cache-Control']); // Redirect to the correct one.
$this->assertEquals($url, $current_url);
// And again to confirm it's not cached on disk.
$session->visit($this->replaceGroupHash($url));
$this->assertSession()->statusCodeEquals(200);
$headers = $session->getResponseHeaders();
$this->assertEquals(['no-store, private'], $headers['Cache-Control']);
} }
/** /**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment