/var/www/vhosts/ihelp.ro/_OLD/vendor/cakephp/cakephp/src/Http
Edit: /var/www/vhosts/ihelp.ro/_OLD/vendor/cakephp/cakephp/src/Http/CorsBuilder.php (5999B)
_origin = $origin;
$this->_isSsl = $isSsl;
$this->_response = $response;
}
/**
* 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.
*
* @return \Psr\Http\Message\MessageInterface A new instance of the response with new headers.
*/
public function build(): MessageInterface
{
$response = $this->_response;
if (empty($this->_origin)) {
return $response;
}
if (isset($this->_headers['Access-Control-Allow-Origin'])) {
foreach ($this->_headers as $key => $value) {
$response = $response->withHeader($key, $value);
}
}
return $response;
}
/**
* 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
*
* @param string|string[] $domains The allowed domains
* @return $this
*/
public function allowOrigin($domains)
{
$allowed = $this->_normalizeDomains((array)$domains);
foreach ($allowed as $domain) {
if (!preg_match($domain['preg'], $this->_origin)) {
continue;
}
$value = $domain['original'] === '*' ? '*' : $this->_origin;
$this->_headers['Access-Control-Allow-Origin'] = $value;
break;
}
return $this;
}
/**
* Normalize the origin to regular expressions and put in an array format
*
* @param string[] $domains Domain names to normalize.
* @return array
*/
protected function _normalizeDomains(array $domains): array
{
$result = [];
foreach ($domains as $domain) {
if ($domain === '*') {
$result[] = ['preg' => '@.@', 'original' => '*'];
continue;
}
$original = $preg = $domain;
if (strpos($domain, '://') === false) {
$preg = ($this->_isSsl ? 'https://' : 'http://') . $domain;
}
$preg = '@^' . str_replace('\*', '.*', preg_quote($preg, '@')) . '$@';
$result[] = compact('original', 'preg');
}
return $result;
}
/**
* Set the list of allowed HTTP Methods.
*
* @param string[] $methods The allowed HTTP methods
* @return $this
*/
public function allowMethods(array $methods)
{
$this->_headers['Access-Control-Allow-Methods'] = implode(', ', $methods);
return $this;
}
/**
* Enable cookies to be sent in CORS requests.
*
* @return $this
*/
public function allowCredentials()
{
$this->_headers['Access-Control-Allow-Credentials'] = 'true';
return $this;
}
/**
* Allowed headers that can be sent in CORS requests.
*
* @param string[] $headers The list of headers to accept in CORS requests.
* @return $this
*/
public function allowHeaders(array $headers)
{
$this->_headers['Access-Control-Allow-Headers'] = implode(', ', $headers);
return $this;
}
/**
* Define the headers a client library/browser can expose to scripting
*
* @param string[] $headers The list of headers to expose CORS responses
* @return $this
*/
public function exposeHeaders(array $headers)
{
$this->_headers['Access-Control-Expose-Headers'] = implode(', ', $headers);
return $this;
}
/**
* Define the max-age preflight OPTIONS requests are valid for.
*
* @param int|string $age The max-age for OPTIONS requests in seconds
* @return $this
*/
public function maxAge($age)
{
$this->_headers['Access-Control-Max-Age'] = $age;
return $this;
}
}