CanonicalURLMiddleware
class CanonicalURLMiddleware implements HTTPMiddleware (View source)
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
Properties
protected | bool | $forceWWW | Set if we should redirect to WWW |
|
protected | bool | $forceSSL | Set if we should force SSL |
|
protected | bool|null | $forceBasicAuthToSSL | Set if we should automatically redirect basic auth requests to HTTPS. A null value (default) will cause this property to return the value of the forceSSL property. |
|
protected | int | $redirectType | Redirect type |
|
protected | array|bool | $enabledEnvs | Environment variables this middleware is enabled in, or a fixed boolean flag to
apply to all environments. cli is disabled unless present here as |
|
protected | array | $forceSSLPatterns | If forceSSL is enabled, this is the list of patterns that the url must match (at least one) |
|
protected | string | $forceSSLDomain | SSL Domain to use |
Methods
An implementation of the factory method, allows you to create an instance of a class
Creates a class instance by the "singleton" design pattern.
Handles redirection to canonical urls outside of the main middleware chain using HTTPResponseException.
Return a valid request, if one is available, or null if none is available
Set enabled flag, or list of environments to enable in.
Determine whether the executed middlewares have added a basic authentication prompt
Redirect the current URL to the specified HTTP scheme
Details
static Injectable
create(mixed ...$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::class); $list = SiteTree::get();
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).
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
HTTPResponse
process(HTTPRequest $request, callable $delegate)
Generate response for the given request
protected HTTPResponse|null
getRedirect(HTTPRequest $request)
Given request object determine if we should redirect.
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
protected HTTPRequest|null
getOrValidateRequest(HTTPRequest $request = null)
Return a valid request, if one is available, or null if none is available
protected bool
requiresSSL(HTTPRequest $request)
Check if a redirect for SSL is necessary
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.
Note: CLI is disabled by default, so "cli"(string)
or true(bool)
should be specified if you wish to
enable for testing.
protected
isEnabled()
Ensure this middleware is enabled
protected bool
hasBasicAuthPrompt(HTTPResponse $response = null)
Determine whether the executed middlewares have added a basic authentication prompt
protected HTTPResponse
redirectToScheme(HTTPRequest $request, string $scheme, string $host = null)
Redirect the current URL to the specified HTTP scheme