diff --git a/core/lib/Drupal/Component/HttpFoundation/SecuredRedirectResponse.php b/core/lib/Drupal/Component/HttpFoundation/SecuredRedirectResponse.php index 77c978c..66cbf36 100644 --- a/core/lib/Drupal/Component/HttpFoundation/SecuredRedirectResponse.php +++ b/core/lib/Drupal/Component/HttpFoundation/SecuredRedirectResponse.php @@ -33,12 +33,19 @@ */ public static function createFromRedirectResponse(RedirectResponse $response) { $safe_response = new static($response->getTargetUrl(), $response->getStatusCode(), $response->headers->allPreserveCase()); - $safe_response->setProtocolVersion($response->getProtocolVersion()); - $safe_response->setCharset($response->getCharset()); + $safe_response->fromResponse($response); return $safe_response; } /** + * Copies over the values from the given response. + */ + protected function fromResponse(RedirectResponse $response) { + $this->setProtocolVersion($response->getProtocolVersion()); + $this->setCharset($response->getCharset()); + } + + /** * {@inheritdoc} */ public function setTargetUrl($url) { diff --git a/core/lib/Drupal/Core/Cache/CacheableRedirectResponse.php b/core/lib/Drupal/Core/Cache/CacheableRedirectResponse.php index d4ba48c..7d949ff 100644 --- a/core/lib/Drupal/Core/Cache/CacheableRedirectResponse.php +++ b/core/lib/Drupal/Core/Cache/CacheableRedirectResponse.php @@ -19,7 +19,7 @@ * @see \Drupal\Core\Cache\CacheableMetadata * @see \Drupal\Core\Cache\CacheableResponseTrait */ -class CacheableRedirectResponse extends RedirectResponse implements CacheableRedirectResponseInterface { +class CacheableRedirectResponse extends RedirectResponse implements CacheableResponseInterface { use CacheableResponseTrait; diff --git a/core/lib/Drupal/Core/Cache/CacheableRedirectResponseInterface.php b/core/lib/Drupal/Core/Cache/CacheableRedirectResponseInterface.php deleted file mode 100644 index a35842a..0000000 --- a/core/lib/Drupal/Core/Cache/CacheableRedirectResponseInterface.php +++ /dev/null @@ -1,18 +0,0 @@ -getCacheableMetadata(); + if ($response instanceof CacheableResponseInterface) { + $metadata->merge($response->getCacheableMetadata()); + } + else { + $metadata->setCacheMaxAge(0); + } + } + } diff --git a/core/lib/Drupal/Core/Routing/TrustedRedirectResponse.php b/core/lib/Drupal/Core/Routing/TrustedRedirectResponse.php index c7a43a2..b218652 100644 --- a/core/lib/Drupal/Core/Routing/TrustedRedirectResponse.php +++ b/core/lib/Drupal/Core/Routing/TrustedRedirectResponse.php @@ -8,14 +8,18 @@ namespace Drupal\Core\Routing; use Drupal\Component\HttpFoundation\SecuredRedirectResponse; +use Drupal\Core\Cache\CacheableResponseInterface; +use Drupal\Core\Cache\CacheableResponseTrait; +use Symfony\Component\HttpFoundation\RedirectResponse; /** * Provides a redirect response which contains trusted URLs. * * Use this class in case you know that you want to redirect to an external URL. */ -class TrustedRedirectResponse extends SecuredRedirectResponse { +class TrustedRedirectResponse extends SecuredRedirectResponse implements CacheableResponseInterface { + use CacheableResponseTrait; use LocalAwareRedirectResponseTrait; /** @@ -28,6 +32,21 @@ class TrustedRedirectResponse extends SecuredRedirectResponse { /** * {@inheritdoc} */ + protected function fromResponse(RedirectResponse $response) { + parent::fromResponse($response); + + $metadata = $this->getCacheableMetadata(); + if ($response instanceof CacheableResponseInterface) { + $metadata->merge($response->getCacheableMetadata()); + } + else { + $metadata->setCacheMaxAge(0); + } + } + + /** + * {@inheritdoc} + */ public function __construct($url, $status = 302, $headers = array()) { $this->trustedUrls[$url] = TRUE; parent::__construct($url, $status, $headers); diff --git a/core/lib/Drupal/Core/Routing/UrlGeneratorTrait.php b/core/lib/Drupal/Core/Routing/UrlGeneratorTrait.php index 639fef0..7f355b2 100644 --- a/core/lib/Drupal/Core/Routing/UrlGeneratorTrait.php +++ b/core/lib/Drupal/Core/Routing/UrlGeneratorTrait.php @@ -56,7 +56,7 @@ protected function url($route_name, $route_parameters = array(), $options = arra * (optional) The HTTP redirect status code for the redirect. The default is * 302 Found. * - * @return \Drupal\Core\Cache\CacheableRedirectResponseInterface + * @return \Drupal\Core\Cache\CacheableRedirectResponse * A redirect response object that may be returned by the controller. */ protected function redirect($route_name, array $route_parameters = [], array $options = [], $status = 302) {