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 Request::cors().
Property Summary
- 
        $_headers protectedarrayThe headers that have been queued so far. 
- 
        $_isSsl protectedboolWhether or not the request was over SSL. 
- 
        $_origin protectedstringThe request's Origin header value 
- 
        $_response protectedCake\Http\ResponseThe response object this builder is attached to. 
Method Summary
- 
          __construct() publicConstructor. 
- 
          _normalizeDomains() protectedNormalize the origin to regular expressions and put in an array format 
- 
          allowCredentials() publicEnable cookies to be sent in CORS requests. 
- 
          allowHeaders() publicWhitelist headers that can be sent in CORS requests. 
- 
          allowMethods() publicSet the list of allowed HTTP Methods. 
- 
          allowOrigin() publicSet the list of allowed domains. 
- 
          build() publicApply the queued headers to the response. 
- 
          exposeHeaders() publicDefine the headers a client library/browser can expose to scripting 
- 
          maxAge() publicDefine the max-age preflight OPTIONS requests are valid for. 
Method Detail
__construct() ¶ public
__construct(Cake\Http\Response $response, string $origin, bool $isSsl = false)Constructor.
Parameters
- 
                Cake\Http\Response$response
- The response object to add headers onto. 
- 
                string$origin
- The request's Origin header. 
- 
                bool$isSsl optional
- Whether or not the request was over SSL. 
_normalizeDomains() ¶ protected
_normalizeDomains(array $domains): arrayNormalize the origin to regular expressions and put in an array format
Parameters
- 
                array$domains
- Domain names to normalize. 
Returns
arrayallowCredentials() ¶ public
allowCredentials(): $thisEnable cookies to be sent in CORS requests.
Returns
$thisallowHeaders() ¶ public
allowHeaders(array $headers): $thisWhitelist headers that can be sent in CORS requests.
Parameters
- 
                array$headers
- The list of headers to accept in CORS requests. 
Returns
$thisallowMethods() ¶ public
allowMethods(array $methods): $thisSet the list of allowed HTTP Methods.
Parameters
- 
                array$methods
- The allowed HTTP methods 
Returns
$thisallowOrigin() ¶ public
allowOrigin(string|array $domain): $thisSet 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
$thisbuild() ¶ public
build(): Cake\Http\ResponseApply 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
Cake\Http\ResponseexposeHeaders() ¶ public
exposeHeaders(array $headers): $thisDefine the headers a client library/browser can expose to scripting
Parameters
- 
                array$headers
- The list of headers to expose CORS responses 
Returns
$thismaxAge() ¶ public
maxAge(int $age): $thisDefine the max-age preflight OPTIONS requests are valid for.
Parameters
- 
                int$age
- The max-age for OPTIONS requests in seconds 
Returns
$this