Cors
in package
Cross Origin Resource Sharing.
TODO conditional safe headers: content-type, accept, accept-language, content-language TODO conditional safe is unsafe: >128 characters TODO restricting origins TODO support for max-age, caching 'options' requests
Table of Contents
Constants
- DEFAULT_CONFIG : mixed = ['origins' => ['*'], 'methods' => ['get'], 'hea...
- SAFE_HEADERS : mixed = [ // Browser headers. 'if-modified-since', 'upg...
Methods
- getOrigin() : string|null
- Get the origin of the request.
- handleCors() : void
- Handling a CORS request.
- isCors() : bool
- Is this a CORS request?
Constants
DEFAULT_CONFIG
public
mixed
DEFAULT_CONFIG
= ['origins' => ['*'], 'methods' => ['get'], 'headers' => ['accept', 'accept-language', 'content-type', 'x-requested-with', 'from', 'dnt', 'via'], 'allow_credentials' => false, 'ignore_headers' => false, 'expose_headers' => false]
SAFE_HEADERS
public
mixed
SAFE_HEADERS
= [
// Browser headers.
'if-modified-since',
'upgrade-insecure-requests',
'accept-encoding',
'connection',
'user-agent',
'host',
'referer',
'cookie',
// CORS safe headers.
'cache-control',
'content-language',
'content-length',
'content-type',
'expires',
'last-modified',
'pragma',
'range',
// CORS headers.
'origin',
'access-control-request-headers',
'access-control-request-method',
]
Methods
getOrigin()
Get the origin of the request.
public
static getOrigin() : string|null
Return values
string|nullhandleCors()
Handling a CORS request.
public
static handleCors([array<string|int, mixed> $config = [] ]) : void
This is a work-in-progress. CORS is a big thing so there's some edge cases that this doesn't yet handle.
Parameters
- $config : array<string|int, mixed> = []
-
[ headers, methods ]
Tags
Return values
void —exits if invalid or pre-flight
isCors()
Is this a CORS request?
public
static isCors() : bool