.../Drupal/Core/EventSubscriber/FinalExceptionSubscriber.php | 12 +----------- .../basic_auth/src/Authentication/Provider/BasicAuth.php | 4 +++- .../rest/tests/src/Functional/BasicAuthResourceTestTrait.php | 4 ++-- 3 files changed, 6 insertions(+), 14 deletions(-) diff --git a/core/lib/Drupal/Core/EventSubscriber/FinalExceptionSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/FinalExceptionSubscriber.php index d65eefa..4317ff0 100644 --- a/core/lib/Drupal/Core/EventSubscriber/FinalExceptionSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/FinalExceptionSubscriber.php @@ -3,8 +3,6 @@ namespace Drupal\Core\EventSubscriber; use Drupal\Component\Utility\SafeMarkup; -use Drupal\Core\Cache\CacheableResponse; -use Drupal\Core\Cache\Exception\CacheableHttpExceptionInterface; use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\Utility\Error; @@ -127,15 +125,7 @@ public function onException(GetResponseForExceptionEvent $event) { $content = $this->t('The website encountered an unexpected error. Please try again later.'); $content .= $message ? '

' . $message : ''; - - // If the exception is cacheable, generate a cacheable response. - if ($exception instanceof CacheableHttpExceptionInterface) { - $response = new CacheableResponse($content, 500, ['Content-Type' => 'text/plain']); - $response->addCacheableDependency($exception->getCacheableMetadata()); - } - else { - $response = new Response($content, 500, ['Content-Type' => 'text/plain']); - } + $response = new Response($content, 500, ['Content-Type' => 'text/plain']); if ($exception instanceof HttpExceptionInterface) { $response->setStatusCode($exception->getStatusCode()); diff --git a/core/modules/basic_auth/src/Authentication/Provider/BasicAuth.php b/core/modules/basic_auth/src/Authentication/Provider/BasicAuth.php index 4d347bd..e49bb67 100644 --- a/core/modules/basic_auth/src/Authentication/Provider/BasicAuth.php +++ b/core/modules/basic_auth/src/Authentication/Provider/BasicAuth.php @@ -127,7 +127,8 @@ public function authenticate(Request $request) { * {@inheritdoc} */ public function challengeException(Request $request, \Exception $previous) { - $site_name = $this->configFactory->get('system.site')->get('name'); + $site_config = $this->configFactory->get('system.site'); + $site_name = $site_config->get('name'); $challenge = SafeMarkup::format('Basic realm="@realm"', [ '@realm' => !empty($site_name) ? $site_name : 'Access restricted', ]); @@ -155,6 +156,7 @@ public function challengeException(Request $request, \Exception $previous) { ->setCacheTags(['config:user.role.anonymous']) ->setCacheContexts(['user.roles:anonymous']) ); + $exception->addCacheableDependency($site_config); return $exception; } diff --git a/core/modules/rest/tests/src/Functional/BasicAuthResourceTestTrait.php b/core/modules/rest/tests/src/Functional/BasicAuthResourceTestTrait.php index 24a6b21..fd3961f 100644 --- a/core/modules/rest/tests/src/Functional/BasicAuthResourceTestTrait.php +++ b/core/modules/rest/tests/src/Functional/BasicAuthResourceTestTrait.php @@ -40,10 +40,10 @@ protected function assertResponseWhenMissingAuthentication($method, ResponseInte // https://www.drupal.org/node/2877528). When either of those issues is // fixed, remove the if-test and the 'else' block. if ($method === 'GET' && strpos($this->entity->getEntityType()->getLinkTemplate('canonical'), '/admin/') !== 0) { - $this->assertResourceErrorResponse(401, 'No authentication credentials provided.', $response, ['4xx-response', 'config:user.role.anonymous', 'http_response'], ['user.roles:anonymous'], $expected_page_cache_header_value, $expected_page_cache_header_value); + $this->assertResourceErrorResponse(401, 'No authentication credentials provided.', $response, ['4xx-response', 'config:system.site', 'config:user.role.anonymous', 'http_response'], ['user.roles:anonymous'], $expected_page_cache_header_value, $expected_page_cache_header_value); } else { - $this->assertResourceErrorResponse(401, 'No authentication credentials provided.', $response, ['4xx-response', 'config:user.role.anonymous', 'http_response'], ['user.roles:anonymous'], $expected_page_cache_header_value, FALSE); + $this->assertResourceErrorResponse(401, 'No authentication credentials provided.', $response, ['4xx-response', 'config:system.site', 'config:user.role.anonymous', 'http_response'], ['user.roles:anonymous'], $expected_page_cache_header_value, FALSE); } }