Check if we should put the status code in the output and force a 200 OK
in the header

@param Request $request
@param SymfonyResponse $response
@param ResponseModelInterface $responseModel
348630
protected function forceStatusCodeHttpOK(
        Request $request,
        SymfonyResponse $response,
        ResponseModelInterface $responseModel
    ) {
        if ($request->headers->has('X-Force-Status-Code-200')
            || ($request->getRequestFormat(
                ) == Format::FORMAT_JSON && $request->query->has(
                    self::PARAMETER_CALLBACK
                ))
        ) {
            $responseModel->setReturnStatusCode(true);
            $response->setStatusCode(Response::HTTP_OK);
            $response->headers->set('X-Status-Code', Response::HTTP_OK);
        }
    }
943747
public function canResponseSatisfyFailedRequest(RequestInterface $request, Response $response)
    {
        $reqc = $request->getHeader('Cache-Control');
        $resc = $response->getHeader('Cache-Control');
        $requestStaleIfError = $reqc ? $reqc->getDirective('stale-if-error') : null;
        $responseStaleIfError = $resc ? $resc->getDirective('stale-if-error') : null;

        if (!$requestStaleIfError && !$responseStaleIfError) {
            return false;
        }

        if (is_numeric($requestStaleIfError) && $response->getAge() - $response->getMaxAge() > $requestStaleIfError) {
            return false;
        }

        if (is_numeric($responseStaleIfError) && $response->getAge() - $response->getMaxAge() > $responseStaleIfError) {
            return false;
        }

        return true;
    }
590793
public function onRequest(Request $request, Response $response)
    {
        // Initialize Request and Response and set to RequestContent
        $psr7Request = \Swoft\Http\Message\Server\Request::loadFromSwooleRequest($request);
        $psr7Response = new \Swoft\Http\Message\Server\Response($response);

        /** @var \Swoft\Http\Server\ServerDispatcher $dispatcher */
        $dispatcher = App::getBean('serverDispatcher');
        $dispatcher->dispatch($psr7Request, $psr7Response);
    }
311169
private function validateResponse(ResponseInterface $response)
    {
        if ($response->getStatusCode() !== 200) {
            $responseData = json_decode((string) $response->getBody(), true);
            $code = isset($responseData['error']['code']) ? $responseData['error']['code'] : 0;
            $message = isset($responseData['error']['message']) ? $responseData['error']['message'] : $response->getReasonPhrase();

            throw new ApiException($message, $code, $responseData);
        }
    }
1315676
public function postRequest(HTTPRequest $request, HTTPResponse $response = null)
    {
        if ($response &&
            preg_match('/text\/html/', $response->getHeader('Content-Type')) &&
            !preg_match('/^(admin|dev)\//', $request->getURL())
        ) {
            $response->setBody(
                $this->obfuscateEmails($response->getBody())
            );
        }
    }
1089584
private function isSuccessful(Response $response): bool
    {
        if ($response->statusCode()->value() !== 200) {
            return false;
        }

        $json = Json::decode((string) $response->body());

        return count($json['errors']) === 0;
    }
580513
protected function getSerializedContent(
        Request $request,
        ResponseModelInterface $responseModel
    ) {
        return $this->serializer->serialize(
            $responseModel->toArray(),
            $request->getRequestFormat()
        );
    }
201152
public function dispatch(Request $request, Response $response) {
		$module = ucfirst($request->module);
		$controller = ucfirst($request->controller);
		$action = ucfirst($request->action);
		$response->setTemplate($controller . '/' . $action);
		$response->setTemplatePath(APP_PATH . 'Module/' . $module . '/View/');
		if (!empty($request->extension)) {
			$response->mimeType($request->extension);
		}
		try {
			$code = self::isValid($module, $controller, $action);
			if ($code === self::ROUTE_VALID) {
				$className = EntryUtil::controller($module, $controller);
				$clazz = Container::getInstance()->get($className);
				$actionName = $action . 'Action';
				$result = $clazz->$actionName($request, $response);
				if ($result !== null) {
					$response->result = $result;
				}
			} else {
				// Not found
				$request->status = $code;
			}
		} catch (\Throwable $e) {
			$request->status = $e;
		}
		$this->executeInterceptor('after', $request, $response);
		$request->end();
		$response->end();
		unset($request, $response);
	}
601207
protected function sendNotModified(HTTPRequest $request, HTTPResponse $response)
    {
        // 304 is invalid for destructive requests
        if (in_array($request->httpMethod(), ['POST', 'DELETE', 'PUT'])) {
            $response->setStatusCode(412);
        } else {
            $response->setStatusCode(304);
        }
        $response->setBody('');
        return $response;
    }
592824
private function sendHttpFoundationResponse(int $requestId, HttpFoundationResponse $response): void
    {
        $statusCode = $response->getStatusCode();

        $headerData  = "Status: {$statusCode}\r\n";
        $headerData .= $response->headers."\r\n";

        $stream = fopen('php://memory', 'r+');
        fwrite($stream, $response->getContent());

        $this->writeResponse($requestId, $headerData, $stream);
    }
641393
public function renderOutput($response = array(), $status=NULL, $message=NULL)
	{
		http_response_code( $status != NULL ? $status : $this->status );
		header('Content-Type: application/json');
		header("Access-Control-Allow-Origin: *");
		header("Access-Control-Allow-Headers: x-auth-token, x-auth-email");
		header('Access-Control-Allow-Methods: PUT, PATCH, DELETE, POST, GET, OPTIONS');

		// Back-convert the string to a boolean
		if ($response === 'false')
			$response = false;

		echo CJSON::encode(array(
               'status' => $status != NULL ? $status : $this->status,
               'message' => $message != NULL ? $message : ($this->message == NULL ? Yii::t('Api.main', 'Your request was successfully fulfilled') : $this->message),
               'response' => $response
           	));
		Yii::app()->end();
	}
428053
private function executePassiveActions(Request $request, Response $response): Response
    {
        foreach ($this->getRouter()->getConfiguration()->getPassiveActions() as $action => $whitelist) {
            $activeAction = $this->getRouter()->getActionAlias($request);

            if (!in_array($activeAction, $whitelist) && !in_array('all', $whitelist)) {
                continue;
            }

            if (in_array('-' . $activeAction, $whitelist) && in_array('all', $whitelist)) {
                continue;
            }

            $route = $this->getRouter()->getAliasedRoute($action, [], Router::PASSIVE_ACTION);

            if (!method_exists($route->getController(), $route->getAction())) {
                throw new ActionNotFoundException($action . ' passive action is present in registry, but can\'t be found or is improperly configured.');
            }

            $controllerName = $route->getController();
            $controller = new $controllerName($this->drivers, $request, $response);
            $response = $controller->{$route->getAction()}(...$route->getActionParams());
        }

        return $response;
    }
1316579
private function cacheVary(
        RequestInterface $request,
        ResponseInterface $response
    ) {
        $key = $this->getVaryKey($request);
        $this->cache->save($key, $this->normalizeVary($response), $this->getTtl($response));
    }
724455
protected function sendResetLinkFailedResponse(Request $request, $response)
    {
        if ($request->expectsJson()) {
            return new JsonResponse([
                'message' =>  'The given data was invalid.',
                'errors' => [
                    'email' => trans($response)
                ]
            ], 422);
        }
        return back()->withErrors(
            ['email' => trans($response)]
        );
    }
454244
protected function forceEmptyResponseOnHttpNoContent(
        SymfonyResponse $response
    ) {
        if ($response->getStatusCode() === Response::HTTP_NO_CONTENT) {
            $response->setContent(null);
            $response->headers->remove('Content-Type');
        }
    }
1201172
protected function updateResponse(Request $request, Response $response)
    {
        $this->stopProfiling(ProfilingCollection::REQUEST_TIMER);

        if ($this->needToUpdateResponse($response)) {
            $data = $this->getResponseData($response);

            if ($data === false) {
                return;
            }

            $data[$this->responseKey] = $this->storage->getData();

            $this->setResponseData($response, $data);
        }
    }
463200
public function executeFilters(Request $request, Response $response)
    {
        $middlewares = $this->filterMiddleware(Filter::class);

        foreach ($middlewares as $middleware) {
            if (($returnResponse = $middleware->doFilter($request, $response)) !== null) {
                return $returnResponse;
            }
            unset($returnResponse);
        }

        unset($middlewares);
    }