CakePHP
  • 文档
    • 书籍
    • API
    • 视频
    • 报告安全问题
    • 隐私政策
    • 徽标和商标
  • 商业解决方案
  • 周边产品
  • 公路旅行
  • 团队
  • 社区
    • 社区
    • 加入我们
    • 问题 (Github)
    • 面包店
    • 特色资源
    • 培训
    • 聚会
    • 我的 CakePHP
    • CakeFest
    • 新闻稿
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • 帮助和支持
    • 论坛
    • Stack Overflow
    • IRC
    • Slack
    • 付费支持
CakePHP

C CakePHP 5.1 Chiffon API

  • 项目
    • CakePHP
      • CakePHP
      • Chronos
      • Elastic Search
      • 队列
  • 版本
    • 5.1
      • 5.1
      • 5.0
      • 4.5
      • 4.4
      • 4.3
      • 4.2
      • 4.1
      • 4.0
      • 3.10
      • 3.9
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

命名空间

  • 全局
  • Cake
    • Cache
    • Collection
    • Command
    • Console
    • Controller
    • Core
    • Database
    • Datasource
    • Error
    • Event
    • Form
    • Http
      • Client
      • Cookie
      • Exception
      • Middleware
      • Session
      • TestSuite
    • I18n
    • Log
    • Mailer
    • Network
    • ORM
    • Routing
    • TestSuite
    • Utility
    • Validation
    • View

CorsBuilder 类

一个帮助定义跨域请求相关标头的构建器对象。

此对象中的每个方法都提供流畅的接口。在设置好要使用的所有标头后,可以使用 build() 方法返回修改后的响应。

通过 Response::cors() 获取此对象最方便。

命名空间: Cake\Http
参见: \Cake\Http\Response::cors()

属性摘要

  • $_headers protected
    array<string, mixed>

    到目前为止已排队的标头。

  • $_isSsl protected
    bool

    请求是否通过 SSL。

  • $_origin protected
    string

    请求的 Origin 标头值

  • $_response protected
    Psr\Http\Message\ResponseInterface

    此构建器所附加的响应对象。

方法摘要

  • __construct() public

    构造函数。

  • _normalizeDomains() protected

    将源规范化为正则表达式并以数组格式存放

  • allowCredentials() public

    允许在 CORS 请求中发送 Cookie。

  • allowHeaders() public

    允许在 CORS 请求中发送的标头。

  • allowMethods() public

    设置允许的 HTTP 方法列表。

  • allowOrigin() public

    设置允许的域列表。

  • build() public

    将排队的标头应用于响应。

  • exposeHeaders() public

    定义客户端库/浏览器可以公开给脚本的标头

  • maxAge() public

    定义预检 OPTIONS 请求有效的最大年龄。

方法详情

__construct() ¶ public

__construct(Psr\Http\Message\ResponseInterface $response, string $origin, bool $isSsl = false)

构造函数。

参数
Psr\Http\Message\ResponseInterface $response

要添加标头的响应对象。

string $origin

请求的 Origin 标头。

bool $isSsl optional

请求是否通过 SSL。

_normalizeDomains() ¶ protected

_normalizeDomains(list<string> $domains): array<array<string, string>>

将源规范化为正则表达式并以数组格式存放

参数
list<string> $domains

要规范化的域名。

返回
array<array<string, string>>

allowCredentials() ¶ public

allowCredentials(): $this

允许在 CORS 请求中发送 Cookie。

返回
$this

allowHeaders() ¶ public

allowHeaders(list<string> $headers): $this

允许在 CORS 请求中发送的标头。

参数
list<string> $headers

要在 CORS 请求中接受的标头列表。

返回
$this

allowMethods() ¶ public

allowMethods(list<string> $methods): $this

设置允许的 HTTP 方法列表。

参数
list<string> $methods

允许的 HTTP 方法

返回
$this

allowOrigin() ¶ public

allowOrigin(list<string>|string $domains): $this

设置允许的域列表。

接受一个字符串或一个启用 CORS 的域数组。可以使用 *.example.com 通配符接受子域,或使用 * 允许所有域

参数
list<string>|string $domains

允许的域

返回
$this

build() ¶ public

build(): Psr\Http\Message\ResponseInterface

将排队的标头应用于响应。

如果构建器没有 Origin,或者没有允许的域,或者允许的域与 Origin 标头不匹配,则不会应用任何标头。

返回
Psr\Http\Message\ResponseInterface

exposeHeaders() ¶ public

exposeHeaders(list<string> $headers): $this

定义客户端库/浏览器可以公开给脚本的标头

参数
list<string> $headers

要公开 CORS 响应的标头列表

返回
$this

maxAge() ¶ public

maxAge(string|int $age): $this

定义预检 OPTIONS 请求有效的最大年龄。

参数
string|int $age

OPTIONS 请求的最大年龄(以秒为单位)

返回
$this

属性详情

$_headers ¶ protected

到目前为止已排队的标头。

类型
array<string, mixed>

$_isSsl ¶ protected

请求是否通过 SSL。

类型
bool

$_origin ¶ protected

请求的 Origin 标头值

类型
string

$_response ¶ protected

此构建器所附加的响应对象。

类型
Psr\Http\Message\ResponseInterface
OpenHub
Pingping
Linode
  • 商业解决方案
  • 展示
  • 文档
  • 书籍
  • API
  • 视频
  • 报告安全问题
  • 隐私政策
  • 徽标和商标
  • 社区
  • 加入我们
  • 问题 (Github)
  • 面包店
  • 特色资源
  • 培训
  • 聚会
  • 我的 CakePHP
  • CakeFest
  • 新闻稿
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • 帮助和支持
  • 论坛
  • Stack Overflow
  • IRC
  • Slack
  • 付费支持

使用 CakePHP API Docs 生成