-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #2911747 by stevector: Limit header size to avoid 502
- Loading branch information
Showing
12 changed files
with
525 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,13 @@ | ||
services: | ||
logger.channel.pantheon_advanced_page_cache: | ||
parent: logger.channel_base | ||
arguments: ['pantheon_advanced_page_cache'] | ||
pantheon_advanced_page_cache.cache_tags.invalidator: | ||
class: Drupal\pantheon_advanced_page_cache\CacheTagsInvalidator | ||
tags: | ||
- { name: cache_tags_invalidator } | ||
pantheon_advanced_page_cache.cacheable_response_subscriber: | ||
class: Drupal\pantheon_advanced_page_cache\EventSubscriber\CacheableResponseSubscriber | ||
arguments: ['@logger.channel.pantheon_advanced_page_cache'] | ||
tags: | ||
- { name: event_subscriber } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
Feature: Huge Header Warning | ||
In order to understand the caching behavior of my site | ||
As an administrator | ||
I need a notification when my header is truncated. | ||
|
||
@api | ||
Scenario: Warning message. | ||
Given I run drush "pm-uninstall -y pantheon_advanced_page_cache_test" | ||
Given I run drush "en -y pantheon_advanced_page_cache" | ||
And I am logged in as a user with the "administrator" role | ||
|
||
And there are 10 article nodes with a huge number of taxonomy terms each | ||
When I visit "/node" | ||
And I visit "admin/reports/dblog" | ||
And I click "More cache tags were present than could be passed in…" in the "pantheon_advanced_page_cache" row | ||
Then I should see "More cache tags were present than could be passed in the Surrogate-Key HTTP Header due to length constraints" | ||
|
||
@api | ||
Scenario: No warning message after enabling test module. | ||
Given I run drush "en -y pantheon_advanced_page_cache_test" | ||
And I am logged in as a user with the "administrator" role | ||
And I visit "admin/reports/dblog/confirm" | ||
And I press "Confirm" | ||
And there are 10 article nodes with a huge number of taxonomy terms each | ||
When I visit "/node" | ||
And I visit "admin/reports/dblog" | ||
Then I should not see "pantheon_advanced_page_cache" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
tests/modules/pantheon_advanced_page_cache_test/pantheon_advanced_page_cache_test.info.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
name: Pantheon Advanced Page Cache Test | ||
description: 'Used during automated test of Pantheon Advanced Page Cache' | ||
package: Testing | ||
type: module | ||
core: 8.x |
5 changes: 5 additions & 0 deletions
5
.../modules/pantheon_advanced_page_cache_test/pantheon_advanced_page_cache_test.services.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
services: | ||
pantheon_advanced_page_cache_test.cacheable_response_subscriber: | ||
class: Drupal\pantheon_advanced_page_cache_test\EventSubscriber\CacheableResponseSubscriber | ||
tags: | ||
- { name: event_subscriber } |
58 changes: 58 additions & 0 deletions
58
...les/pantheon_advanced_page_cache_test/src/EventSubscriber/CacheableResponseSubscriber.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
namespace Drupal\pantheon_advanced_page_cache_test\EventSubscriber; | ||
|
||
use Drupal\Core\Cache\CacheableResponseInterface; | ||
use Symfony\Component\HttpKernel\Event\FilterResponseEvent; | ||
use Symfony\Component\HttpKernel\KernelEvents; | ||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
|
||
/** | ||
* Adds Surrogate-Key header to cacheable master responses. | ||
*/ | ||
class CacheableResponseSubscriber implements EventSubscriberInterface { | ||
|
||
/** | ||
* Adds Surrogate-Key header to cacheable master responses. | ||
* | ||
* @param \Symfony\Component\HttpKernel\Event\FilterResponseEvent $event | ||
* The event to process. | ||
*/ | ||
public function onRespond(FilterResponseEvent $event) { | ||
if (!$event->isMasterRequest()) { | ||
return; | ||
} | ||
|
||
$response = $event->getResponse(); | ||
|
||
if ($response instanceof CacheableResponseInterface) { | ||
$tags = $response->getCacheableMetadata()->getCacheTags(); | ||
|
||
// This is a contrived example of how custom code can be used | ||
// to limit a giant list of tags. | ||
// In this case, automated Behat tests generate nodes | ||
// tagged in 100s of taxonomy terms each. Then when | ||
// those nodes are rendered on a view like frontpage | ||
// they result in too many total surrogate-keys being set. | ||
if (in_array("config:views.view.frontpage", $tags)) { | ||
$new_tags = []; | ||
foreach ($tags as $tag) { | ||
if (strpos($tag, "taxonomy_term:") === FALSE) { | ||
$new_tags[] = $tag; | ||
} | ||
} | ||
$response->getCacheableMetadata()->setCacheTags($new_tags); | ||
} | ||
|
||
} | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public static function getSubscribedEvents() { | ||
$events[KernelEvents::RESPONSE][] = ['onRespond', 100]; | ||
return $events; | ||
} | ||
|
||
} |