CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Reporting Security Issues
    • Privacy Policy
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Get Involved
    • Issues (Github)
    • Bakery
    • Featured Resources
    • Training
    • Meetups
    • My CakePHP
    • CakeFest
    • Newsletter
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • Help & Support
    • Forum
    • Stack Overflow
    • IRC
    • Slack
    • Paid Support
CakePHP

C CakePHP 6.0 API

  • Project:
    • CakePHP
      • CakePHP
      • Authentication
      • Authorization
      • Chronos
      • Elastic Search
      • Queue
  • Version:
    • 6.0
      • 6.0
      • 5.4
      • 5.3
      • 5.2
      • 5.1
      • 5.0
      • 4.6
      • 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

Namespaces

  • Global
  • Cake
    • AttributeResolver
    • Cache
    • Collection
    • Command
    • Console
    • Container
    • Controller
    • Core
    • Database
    • Datasource
    • Error
    • Event
    • Form
    • Http
      • Client
      • Cookie
      • Exception
      • Link
      • Middleware
      • RateLimit
      • Response
      • Session
      • TestSuite
    • I18n
    • Lock
    • Log
    • Mailer
    • Network
    • ORM
    • Routing
    • TestSuite
    • Utility
    • Validation
    • View

Class CorsBuilder

A builder object that assists in defining Cross Origin Request related headers.

Each of the methods in this object provide a fluent interface. Once you've set all the headers you want to use, the build() method can be used to return a modified Response.

It is most convenient to get this object via Response::cors().

Namespace: Cake\Http
See: \Cake\Http\Response::cors()

Property Summary

  • $headers protected
    array<string, mixed>

    The headers that have been queued so far.

Method Summary

  • __construct() public

    Constructor.

  • allowCredentials() public

    Enable cookies to be sent in CORS requests.

  • allowHeaders() public

    Allowed headers that can be sent in CORS requests.

  • allowMethods() public

    Set the list of allowed HTTP Methods.

  • allowOrigin() public

    Set the list of allowed domains.

    Accepts a string or an array of domains that have CORS enabled. You can use *.example.com wildcards to accept subdomains, or * to allow all domains

  • build() public

    Apply the queued headers to the response.

    If the builder has no Origin, or if there are no allowed domains, or if the allowed domains do not match the Origin header no headers will be applied.

  • exposeHeaders() public

    Define the headers a client library/browser can expose to scripting

  • maxAge() public

    Define the max-age preflight OPTIONS requests are valid for.

  • normalizeDomains() protected

    Normalize the origin to regular expressions and put in an array format

Method Detail

__construct() ¶ public

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

Constructor.

Parameters
Psr\Http\Message\ResponseInterface $response

The response object to add headers onto.

string $origin

The request's Origin header.

bool $isSsl optional

Whether the request was over SSL.

allowCredentials() ¶ public

allowCredentials(): $this

Enable cookies to be sent in CORS requests.

Returns
$this

allowHeaders() ¶ public

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

Allowed headers that can be sent in CORS requests.

Parameters
array<string> $headers

The list of headers to accept in CORS requests.

Returns
$this

allowMethods() ¶ public

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

Set the list of allowed HTTP Methods.

Parameters
array<string> $methods

The allowed HTTP methods

Returns
$this

allowOrigin() ¶ public

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

Set the list of allowed domains.

Accepts a string or an array of domains that have CORS enabled. You can use *.example.com wildcards to accept subdomains, or * to allow all domains

Parameters
array<string>|string $domains

The allowed domains

Returns
$this

build() ¶ public

build(): Psr\Http\Message\ResponseInterface

Apply the queued headers to the response.

If the builder has no Origin, or if there are no allowed domains, or if the allowed domains do not match the Origin header no headers will be applied.

Returns
Psr\Http\Message\ResponseInterface

A new instance of the response with new headers.

exposeHeaders() ¶ public

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

Define the headers a client library/browser can expose to scripting

Parameters
array<string> $headers

The list of headers to expose CORS responses

Returns
$this

maxAge() ¶ public

maxAge(string|int $age): $this

Define the max-age preflight OPTIONS requests are valid for.

Parameters
string|int $age

The max-age for OPTIONS requests in seconds

Returns
$this

normalizeDomains() ¶ protected

normalizeDomains(array<string> $domains): array<array<string, string>>

Normalize the origin to regular expressions and put in an array format

Parameters
array<string> $domains

Domain names to normalize.

Returns
array<array<string, string>>

Property Detail

$headers ¶ protected

The headers that have been queued so far.

Type
array<string, mixed>
OpenHub
Pingping
Linode
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Reporting Security Issues
  • Privacy Policy
  • Logos & Trademarks
  • Community
  • Get Involved
  • Issues (Github)
  • Bakery
  • Featured Resources
  • Training
  • Meetups
  • My CakePHP
  • CakeFest
  • Newsletter
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • Help & Support
  • Forum
  • Stack Overflow
  • IRC
  • Slack
  • Paid Support

Generated using CakePHP API Docs