类 HttpsEnforcerMiddleware
强制请求使用 HTTPS(SSL)。
命名空间: Cake\Http\Middleware
属性摘要
-
$config protected
array<string, mixed>配置。
方法摘要
-
__construct() public
构造函数
-
addHsts() protected
在响应中添加 Strict-Transport-Security 头。
-
process() public
检查请求是否使用 HTTPS 发出。
方法详情
__construct() ¶ public
__construct(array<string, mixed> $config = [])
构造函数
参数
-
array<string, mixed>$config optional 要使用的选项。
另请参阅
\Cake\Http\Middleware\HttpsEnforcerMiddleware::$config
addHsts() ¶ protected
addHsts(Psr\Http\Message\ResponseInterface $response): Psr\Http\Message\ResponseInterface
在响应中添加 Strict-Transport-Security 头。
参数
-
Psr\Http\Message\ResponseInterface$response 响应
返回
Psr\Http\Message\ResponseInterfaceprocess() ¶ public
process(ServerRequestInterface $request, RequestHandlerInterface $handler): Psr\Http\Message\ResponseInterface
检查请求是否使用 HTTPS 发出。
根据配置和请求方法,重定向到具有 https 的相同 URL 或抛出异常。
参数
-
ServerRequestInterface$request 请求。
-
RequestHandlerInterface$handler 请求处理程序。
返回
Psr\Http\Message\ResponseInterface抛出
Cake\Http\Exception\BadRequestException属性详情
$config ¶ protected
配置。
选项
-
redirect- 如果设置为 true(默认),则将 GET 请求重定向到具有 https 的相同 URL。 -
statusCode- 重定向时要使用的状态代码,默认为 301 - 永久重定向。 -
headers- 重定向时响应头的数组。 -
disableOnDebug- 调试开启时是否应该禁用 HTTPS 检查。默认值为true。 -
trustedProxies- 将传递给请求的可信代理的数组。默认为null。 -
'hsts' - 用于 HTTPS 响应配置的 Strict-Transport-Security 头。默认为
null。如果启用,则为配置选项数组 -
'maxAge' -
max-age指令值,以秒为单位。- 'includeSubDomains' - 是否包含
includeSubDomains指令。默认为false。 - 'preload' - 是否包含 'preload' 指令。默认为
false。
- 'includeSubDomains' - 是否包含
类型
array<string, mixed>