CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Team
    • Issues (Github)
    • YouTube Channel
    • Get Involved
    • Bakery
    • Featured Resources
    • Newsletter
    • Certification
    • My CakePHP
    • CakeFest
    • Facebook
    • Twitter
    • Help & Support
    • Forum
    • Stack Overflow
    • IRC
    • Slack
    • Paid Support
CakePHP

C CakePHP 3.8 Red Velvet API

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 3.8
      • 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

  • Cake
    • Auth
      • Storage
    • Cache
      • Engine
    • Collection
      • Iterator
    • Command
    • Console
      • Exception
    • Controller
      • Component
      • Exception
    • Core
      • Configure
        • Engine
      • Exception
      • Retry
    • Database
      • Driver
      • Exception
      • Expression
      • Schema
      • Statement
      • Type
    • Datasource
      • Exception
    • Error
      • Middleware
    • Event
      • Decorator
    • Filesystem
    • Form
    • Http
      • Client
        • Adapter
        • Auth
      • Cookie
      • Exception
      • Middleware
      • Session
    • I18n
      • Formatter
      • Middleware
      • Parser
    • Log
      • Engine
    • Mailer
      • Exception
      • Transport
    • Network
      • Exception
    • ORM
      • Association
      • Behavior
        • Translate
      • Exception
      • Locator
      • Rule
    • Routing
      • Exception
      • Filter
      • Middleware
      • Route
    • Shell
      • Helper
      • Task
    • TestSuite
      • Fixture
      • Stub
    • Utility
      • Exception
    • Validation
    • View
      • Exception
      • Form
      • Helper
      • Widget
  • None

Classes

  • ActionDispatcher
  • BaseApplication
  • Client
  • ControllerFactory
  • CorsBuilder
  • MiddlewareQueue
  • Response
  • ResponseEmitter
  • Runner
  • Server
  • ServerRequest
  • ServerRequestFactory
  • Session

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().

Namespace: Cake\Http
See: \Cake\Http\Response::cors()
Location: Http/CorsBuilder.php

Properties summary

  • $_headers protected
    array
    The headers that have been queued so far.
  • $_isSsl protected
    boolean
    Whether or not the request was over SSL.
  • $_origin protected
    string
    The request's Origin header value
  • $_response protected
    Psr\Http\Message\MessageInterface
    The response object this builder is attached to.

Method Summary

  • __construct() public
    Constructor.
  • _normalizeDomains() protected
    Normalize the origin to regular expressions and put in an array format
  • allowCredentials() public
    Enable cookies to be sent in CORS requests.
  • allowHeaders() public
    Whitelist 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.
  • build() public
    Apply the queued headers to the response.
  • 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.

Method Detail

__construct() public ¶

__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 optional false
Whether or not the request was over SSL.

_normalizeDomains() protected ¶

_normalizeDomains( string[] $domains )

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

Parameters
string[] $domains
Domain names to normalize.
Returns
array

allowCredentials() public ¶

allowCredentials( )

Enable cookies to be sent in CORS requests.

Returns

$this

allowHeaders() public ¶

allowHeaders( array $headers )

Whitelist headers that can be sent in CORS requests.

Parameters
array $headers
The list of headers to accept in CORS requests.
Returns

$this

allowMethods() public ¶

allowMethods( array $methods )

Set the list of allowed HTTP Methods.

Parameters
array $methods
The allowed HTTP methods
Returns

$this

allowOrigin() public ¶

allowOrigin( string|string[] $domains )

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|string[] $domains
The allowed domains
Returns

$this

build() public ¶

build( )

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.

exposeHeaders() public ¶

exposeHeaders( array $headers )

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() public ¶

maxAge( integer $age )

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

Parameters
integer $age
The max-age for OPTIONS requests in seconds
Returns

$this

Properties detail

$_headers ¶

protected array

The headers that have been queued so far.

[]

$_isSsl ¶

protected boolean

Whether or not the request was over SSL.

$_origin ¶

protected string

The request's Origin header value

$_response ¶

protected Psr\Http\Message\MessageInterface

The response object this builder is attached to.

Follow @CakePHP
#IRC
OpenHub
Rackspace
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Logos & Trademarks
  • Community
  • Team
  • Issues (Github)
  • YouTube Channel
  • Get Involved
  • Bakery
  • Featured Resources
  • Newsletter
  • Certification
  • My CakePHP
  • CakeFest
  • Facebook
  • Twitter
  • Help & Support
  • Forum
  • Stack Overflow
  • IRC
  • Slack
  • Paid Support

Generated using CakePHP API Docs