\Cake\HttpCorsBuilder

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 Request::cors().

Summary

Methods
Properties
Constants
__construct()
build()
allowOrigin()
allowMethods()
allowCredentials()
allowHeaders()
exposeHeaders()
maxAge()
No public properties found
No constants found
_normalizeDomains()
$_response
$_origin
$_isSsl
$_headers
N/A
No private methods found
No private properties found
N/A

Properties

$_origin

$_origin : string

The request's Origin header value

Type

string

$_isSsl

$_isSsl : boolean

Whether or not the request was over SSL.

Type

boolean

$_headers

$_headers : array

The headers that have been queued so far.

Type

array

Methods

__construct()

__construct(\Psr\Http\Message\MessageInterface  $response, string  $origin, boolean  $isSsl = false) 

Constructor.

Parameters

\Psr\Http\Message\MessageInterface $response

The response object to add headers onto.

string $origin

The request's Origin header.

boolean $isSsl

Whether or not the request was over SSL.

build()

build() : \Psr\Http\Message\MessageInterface

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\MessageInterface

A new instance of the response with new headers.

allowOrigin()

allowOrigin(string|array  $domain) : $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

string|array $domain

The allowed domains

Returns

$this

allowMethods()

allowMethods(array  $methods) : $this

Set the list of allowed HTTP Methods.

Parameters

array $methods

The allowed HTTP methods

Returns

$this

allowCredentials()

allowCredentials() : $this

Enable cookies to be sent in CORS requests.

Returns

$this

allowHeaders()

allowHeaders(array  $headers) : $this

Whitelist headers that can be sent in CORS requests.

Parameters

array $headers

The list of headers to accept in CORS requests.

Returns

$this

exposeHeaders()

exposeHeaders(array  $headers) : $this

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

Parameters

array $headers

The list of headers to expose CORS responses

Returns

$this

maxAge()

maxAge(integer  $age) : $this

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

Parameters

integer $age

The max-age for OPTIONS requests in seconds

Returns

$this

_normalizeDomains()

_normalizeDomains(array  $domains) : array

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

Parameters

array $domains

Domain names to normalize.

Returns

array