class LocalRedirectResponse extends CacheableSecuredRedirectResponse (View source)

Provides a redirect response which cannot redirect to an external URL.

Traits

Provides a trait which ensures that a URL is safe to redirect to.

Provides an implementation of CacheableResponseInterface.

Properties

protected CacheableMetadata $cacheabilityMetadata

The cacheability metadata.

from  CacheableResponseTrait
protected RequestContext $requestContext

The request context.

from  LocalAwareRedirectResponseTrait

Methods

createFromRedirectResponse(RedirectResponse $response)

Copies an existing redirect response into a safe one.

fromResponse(RedirectResponse $response)

Copies over the values from the given response.

bool
isSafe(string $url)

Returns whether the URL is considered as safe to redirect to.

addCacheableDependency($dependency)

{@inheritdoc}

bool
isLocal(string $url)

Determines whether a path is local.

$this
setRequestContext(RequestContext $request_context)

Sets the request context.

Details

static SecuredRedirectResponse createFromRedirectResponse(RedirectResponse $response)

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

RedirectResponse $response

The original redirect.

Return Value

SecuredRedirectResponse

protected fromResponse(RedirectResponse $response)

Copies over the values from the given response.

Parameters

RedirectResponse $response

The redirect response object.

SecuredRedirectResponse setTargetUrl($url)

{@inheritdoc}

Parameters

$url

Return Value

SecuredRedirectResponse

abstract protected bool isSafe(string $url)

Returns whether the URL is considered as safe to redirect to.

Parameters

string $url

The URL checked for safety.

Return Value

bool

addCacheableDependency($dependency)

{@inheritdoc}

Parameters

$dependency

getCacheableMetadata()

{@inheritdoc}

protected bool isLocal(string $url)

Determines whether a path is local.

Parameters

string $url

The internal path or external URL being linked to, such as "node/34" or "http://example.com/foo".

Return Value

bool

TRUE or FALSE, where TRUE indicates a local path.

protected RequestContext getRequestContext()

Returns the request context.

Return Value

RequestContext

The request context.

$this setRequestContext(RequestContext $request_context)

Sets the request context.

Parameters

RequestContext $request_context

The request context.

Return Value

$this