class CanonicalURLMiddleware implements HTTPMiddleware

Implements the following URL normalisation rules - redirect basic auth requests to HTTPS - force WWW, redirect to the subdomain "www." - force SSL, redirect to https

Traits

A class that can be instantiated or replaced via DI

Methods

static Injectable
create(array $args)

An implementation of the factory method, allows you to create an instance of a class

static Injectable
singleton(string $class = null)

Creates a class instance by the "singleton" design pattern.

array
getForceSSLPatterns()

No description

$this
setForceSSLPatterns(array $forceSSLPatterns)

No description

string
getForceSSLDomain()

No description

$this
setForceSSLDomain(string $forceSSLDomain)

No description

bool
getForceWWW()

No description

$this
setForceWWW(bool $forceWWW)

No description

bool
getForceSSL()

No description

$this
setForceSSL(bool $forceSSL)

No description

$this
setForceBasicAuthToSSL(bool|null $forceBasicAuth)

No description

bool
getForceBasicAuthToSSL()

No description

process(HTTPRequest $request, callable $delegate)

Generate response for the given request

throwRedirectIfNeeded(HTTPRequest $request = null)

Handles redirection to canonical urls outside of the main middleware chain using HTTPResponseException.

int
getRedirectType()

No description

$this
setRedirectType(int $redirectType)

No description

array|bool
getEnabledEnvs()

Get enabled flag, or list of environments to enable in.

$this
setEnabledEnvs(array|bool $enabledEnvs)

Set enabled flag, or list of environments to enable in.

Details

in Injectable at line 26
static Injectable create(array $args)

An implementation of the factory method, allows you to create an instance of a class

This method will defer class substitution to the Injector API, which can be customised via the Config API to declare substitution classes.

This can be called in one of two ways - either calling via the class directly, or calling on Object and passing the class name as the first parameter. The following are equivalent: $list = DataList::create('SiteTree'); $list = SiteTree::get();

Parameters

array $args

Return Value

Injectable

in Injectable at line 43
static Injectable singleton(string $class = null)

Creates a class instance by the "singleton" design pattern.

It will always return the same instance for this class, which can be used for performance reasons and as a simple way to access instance methods which don't rely on instance data (e.g. the custom SilverStripe static handling).

Parameters

string $class Optional classname to create, if the called class should not be used

Return Value

Injectable The singleton instance

at line 82
array getForceSSLPatterns()

Return Value

array

at line 91
$this setForceSSLPatterns(array $forceSSLPatterns)

Parameters

array $forceSSLPatterns

Return Value

$this

at line 100
string getForceSSLDomain()

Return Value

string

at line 109
$this setForceSSLDomain(string $forceSSLDomain)

Parameters

string $forceSSLDomain

Return Value

$this

at line 118
bool getForceWWW()

Return Value

bool

at line 127
$this setForceWWW(bool $forceWWW)

Parameters

bool $forceWWW

Return Value

$this

at line 136
bool getForceSSL()

Return Value

bool

at line 145
$this setForceSSL(bool $forceSSL)

Parameters

bool $forceSSL

Return Value

$this

at line 155
$this setForceBasicAuthToSSL(bool|null $forceBasicAuth)

Parameters

bool|null $forceBasicAuth

Return Value

$this

at line 164
bool getForceBasicAuthToSSL()

Return Value

bool

at line 181
HTTPResponse process(HTTPRequest $request, callable $delegate)

Generate response for the given request

Parameters

HTTPRequest $request
callable $delegate

Return Value

HTTPResponse

at line 247
throwRedirectIfNeeded(HTTPRequest $request = null)

Handles redirection to canonical urls outside of the main middleware chain using HTTPResponseException.

Will not do anything if a current HTTPRequest isn't available

Parameters

HTTPRequest $request Allow HTTPRequest to be used for the base comparison

Exceptions

HTTPResponse_Exception

at line 315
int getRedirectType()

Return Value

int

at line 324
$this setRedirectType(int $redirectType)

Parameters

int $redirectType

Return Value

$this

at line 335
array|bool getEnabledEnvs()

Get enabled flag, or list of environments to enable in.

Return Value

array|bool

at line 348
$this setEnabledEnvs(array|bool $enabledEnvs)

Set enabled flag, or list of environments to enable in.

Note: CLI is disabled by default, so "cli"(string) or true(bool) should be specified if you wish to enable for testing.

Parameters

array|bool $enabledEnvs

Return Value

$this