code: public function beforeAction($action)
      {
          $this->request = $this->request ?: Yii::$app->getRequest();
          $this->response = $this->response ?: Yii::$app->getResponse();
  
          $this->overrideDefaultSettings($action);
  
          $requestCorsHeaders = $this->extractHeaders();
          $responseCorsHeaders = $this->prepareHeaders($requestCorsHeaders);
          $this->addCorsHeaders($this->response, $responseCorsHeaders);
  
          if ($this->request->isOptions && $this->request->headers->has('Access-Control-Request-Method')) {
              // it is CORS preflight request, respond with 200 OK without further processing
              $this->response->setStatusCode(200);
              return false;
          }
  
          return true;
      }
docs: {@inheritdoc}