PHPDaemon\SockJS\Methods\Generic::CORS PHP Method

CORS() protected method

CORS
protected CORS ( ) : void
return void
    protected function CORS()
    {
        if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS'])) {
            $this->header('Access-Control-Allow-Headers: ' . $_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']);
        }
        if (isset($_SERVER['HTTP_ORIGIN']) && $_SERVER['HTTP_ORIGIN'] !== 'null') {
            $this->header('Access-Control-Allow-Origin:' . $_SERVER['HTTP_ORIGIN']);
        } else {
            $this->header('Access-Control-Allow-Origin: *');
        }
        $this->header('Access-Control-Allow-Credentials: true');
        if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
            $this->header('204 No Content');
            $this->header('Cache-Control: max-age=31536000, public, pre-check=0, post-check=0');
            $this->header('Access-Control-Max-Age: 31536000');
            $this->header('Access-Control-Allow-Methods: OPTIONS, ' . $this->allowedMethods);
            $this->header('Expires: ' . date('r', strtotime('+1 year')));
            $this->finish();
        } elseif (!in_array($_SERVER['REQUEST_METHOD'], explode(', ', $this->allowedMethods), true)) {
            $this->header('405 Method Not Allowed');
            $this->finish();
        }
    }