.../HttpFoundation/SecuredRedirectResponse.php | 22 ++++++------- .../Routing/CacheableSecuredRedirectResponse.php | 37 ++++++++++++++++++++++ .../Drupal/Core/Routing/LocalRedirectResponse.php | 4 +-- .../Core/Routing/TrustedRedirectResponse.php | 4 +-- 4 files changed, 49 insertions(+), 18 deletions(-) diff --git a/core/lib/Drupal/Component/HttpFoundation/SecuredRedirectResponse.php b/core/lib/Drupal/Component/HttpFoundation/SecuredRedirectResponse.php index 02b0f41..66cbf36 100644 --- a/core/lib/Drupal/Component/HttpFoundation/SecuredRedirectResponse.php +++ b/core/lib/Drupal/Component/HttpFoundation/SecuredRedirectResponse.php @@ -7,8 +7,6 @@ namespace Drupal\Component\HttpFoundation; -use Drupal\Core\Cache\CacheableRedirectResponse; -use Drupal\Core\Cache\CacheableResponseInterface; use \Symfony\Component\HttpFoundation\RedirectResponse; /** @@ -20,7 +18,7 @@ * For local URLs we use LocalRedirectResponse which opts * out of external redirects. */ -abstract class SecuredRedirectResponse extends CacheableRedirectResponse { +abstract class SecuredRedirectResponse extends RedirectResponse { /** * Copies an existing redirect response into a safe one. @@ -35,19 +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()); - $metadata = $safe_response->getCacheableMetadata(); - if ($response instanceof CacheableResponseInterface) { - $metadata->addCacheableDependency($response->getCacheableMetadata()); - } - else { - $metadata->setCacheMaxAge(0); - } + $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/Routing/CacheableSecuredRedirectResponse.php b/core/lib/Drupal/Core/Routing/CacheableSecuredRedirectResponse.php new file mode 100644 index 0000000..c8d0244 --- /dev/null +++ b/core/lib/Drupal/Core/Routing/CacheableSecuredRedirectResponse.php @@ -0,0 +1,37 @@ +getCacheableMetadata(); + if ($response instanceof CacheableResponseInterface) { + $metadata->addCacheableDependency($response->getCacheableMetadata()); + } + else { + $metadata->setCacheMaxAge(0); + } + } + +} diff --git a/core/lib/Drupal/Core/Routing/LocalRedirectResponse.php b/core/lib/Drupal/Core/Routing/LocalRedirectResponse.php index d8ad719..4d0e275 100644 --- a/core/lib/Drupal/Core/Routing/LocalRedirectResponse.php +++ b/core/lib/Drupal/Core/Routing/LocalRedirectResponse.php @@ -7,12 +7,10 @@ namespace Drupal\Core\Routing; -use Drupal\Component\HttpFoundation\SecuredRedirectResponse; - /** * Provides a redirect response which cannot redirect to an external URL. */ -class LocalRedirectResponse extends SecuredRedirectResponse { +class LocalRedirectResponse extends CacheableSecuredRedirectResponse { use LocalAwareRedirectResponseTrait { LocalAwareRedirectResponseTrait::isLocal as isSafe; diff --git a/core/lib/Drupal/Core/Routing/TrustedRedirectResponse.php b/core/lib/Drupal/Core/Routing/TrustedRedirectResponse.php index c7a43a2..3beb176 100644 --- a/core/lib/Drupal/Core/Routing/TrustedRedirectResponse.php +++ b/core/lib/Drupal/Core/Routing/TrustedRedirectResponse.php @@ -7,14 +7,12 @@ namespace Drupal\Core\Routing; -use Drupal\Component\HttpFoundation\SecuredRedirectResponse; - /** * 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 CacheableSecuredRedirectResponse { use LocalAwareRedirectResponseTrait;