function SecuredRedirectResponse::createFromRedirectResponse

Same name in other branches
  1. 8.9.x core/lib/Drupal/Component/HttpFoundation/SecuredRedirectResponse.php \Drupal\Component\HttpFoundation\SecuredRedirectResponse::createFromRedirectResponse()
  2. 10 core/lib/Drupal/Component/HttpFoundation/SecuredRedirectResponse.php \Drupal\Component\HttpFoundation\SecuredRedirectResponse::createFromRedirectResponse()
  3. 11.x core/lib/Drupal/Component/HttpFoundation/SecuredRedirectResponse.php \Drupal\Component\HttpFoundation\SecuredRedirectResponse::createFromRedirectResponse()

Copies an existing redirect response into a safe one.

The safe one cannot accidentally redirect to an external URL, unless actively wanted (see TrustedRedirectResponse).

Parameters

\Symfony\Component\HttpFoundation\RedirectResponse $response: The original redirect.

Return value

static

File

core/lib/Drupal/Component/HttpFoundation/SecuredRedirectResponse.php, line 29

Class

SecuredRedirectResponse
Provides a common base class for safe redirects.

Namespace

Drupal\Component\HttpFoundation

Code

public static function createFromRedirectResponse(RedirectResponse $response) {
    $safe_response = new static($response->getTargetUrl(), $response->getStatusCode(), $response->headers
        ->allPreserveCase());
    $safe_response->fromResponse($response);
    return $safe_response;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.