Scalr\Api\Rest\ApiApplication::preflightRequestHandlerMiddleware PHP Method

preflightRequestHandlerMiddleware() public method

Preflight request middleware handler
    public function preflightRequestHandlerMiddleware()
    {
        $origin = $this->request->getOrigin();
        $requestMethod = $this->request->getMethod();
        if (!(empty($this->request->getUserAgent()) || empty($origin))) {
            $allowedOrigins = (array) Scalr::getContainer()->config('scalr.system.api.allowed_origins');
            if (!empty($allowedOrigins)) {
                $this->response->setHeader('Access-Control-Allow-Origin', array_intersect(['*', $origin], $allowedOrigins) ? $origin : implode(' ', $allowedOrigins));
                $this->response->setHeader('Vary', 'Origin, User-Agent');
            }
            if ($requestMethod === Request::METHOD_OPTIONS) {
                $this->response->setHeader('Access-Control-Allow-Methods', 'GET, HEAD, POST, PATCH, PUT, DELETE, OPTIONS');
                $this->response->setHeader('Access-Control-Allow-Headers', 'Content-Type, X-Scalr-Date, X-Scalr-Key-Id, X-Scalr-Signature, X-Scalr-Debug');
                $this->stop();
            }
        } else {
            if ($requestMethod === Request::METHOD_OPTIONS) {
                $this->response->setHeader('Allow', 'GET, HEAD, POST, PATCH, PUT, DELETE, OPTIONS');
                $this->stop();
            }
        }
    }