Called when the server receive a Http request.

@param \Lawoole\Server\Server $server
@param \Lawoole\Server\ServerSockets\ServerSocket $serverSocket
@param \Swoole\Http\Request $request
@param \Swoole\Http\Response $response
4421
public function onRequest($server, $serverSocket, $request, $response)
    {
        try {
            $serializer = $this->getSerializer($serverSocket);

            $message = $serializer->deserialize($request->rawcontent());

            $result = $this->dispatcher->handleMessage($message);

            $body = $serializer->serialize($result);

            $this->respond($response, 200, $body);
        } catch (Throwable $e) {
            Log::channel('homer')->warning('Handle invoking failed, cause: '.$e->getMessage(), [
                'exception' => $e
            ]);

            $this->respond($response, 500, $e->getMessage());
        }
    }
941579
public function checkElementKey(ServerRequest $request, Response $response): Response
    {
        $elementKey = $request->getQueryParams()['key'];

        $objectManager = GeneralUtility::makeInstance(ObjectManager::class);
        $storageRepository = $objectManager->get(StorageRepository::class);

        $isAvailable = true;
        if ($storageRepository->loadElement('tt_content', $elementKey)) {
            $isAvailable = false;
        }

        return new JsonResponse(['isAvailable' => $isAvailable]);
    }
479261
public static function createFromServerRequest(ServerRequest $serverRequest)
    {
        return new Request(
            $serverRequest->getMethod(),
            $serverRequest->getUri(),
            $serverRequest->getHeaders(),
            $serverRequest->getBody(),
            $serverRequest->getProtocolVersion()
        );
    }
867111
private function call(ServerRequestInterface $serverRequest, Route $route)
    {
        ob_start();

        try {
            $result = call_user_func(
                [
                    $this->container->resolve($route->getClass(), null),
                    $route->getMethod()
                ],
                new Request(
                    $serverRequest,
                    $this->container->get(ResponseFactoryInterface::class),
                    $this->container->get(ViewFactory::class),
                    $route
                )
            );

            if ($result instanceof ResponseInterface) {
                $response = $result;
            } else {
                $output = ob_get_contents();

                $response = $this->responseFactory->createResponse(200);
                $response->getBody()->write($result === null ? (string)$output : (string)$result);
            }

            ob_end_clean();
        } catch (\Exception $e) {
            ob_end_clean();
            throw $e;
        }

        return $this->addHeaders($response, $route);
    }
1007736
public function middleware($request, &$response)
    {
        $that = $this;
        if ($middleware = current($this->middleware)) {
            next($this->middleware);
            $middleware->next($request, $response, function ($request, $response) use ($that) {
                $that->middleware($request, $response);
            });
        }
    }
1046933
public function postProcess(Request $request, Response $response)
    {
        if (empty($this->allowedOriginHosts) || !$request->hasHeader('HTTP_ORIGIN')) {
            return;
        }

        $originHost = $request->readHeader('HTTP_ORIGIN')->unsecure();
        foreach ($this->allowedOriginHosts as $allowedOriginHost) {
            if (preg_match('~' . $allowedOriginHost . '~', $originHost) === 1) {
                $response->addHeader('Access-Control-Allow-Origin', $originHost);
            }
        }
    }
256258
public function executeMiddlewares(
        ServerRequestInterface $request,
        ResponseInterface $response,
        callable $next = null
    ) : ResponseInterface {
        return $this->getMiddlewares()->__invoke($request, $response, $next);
    }
970046
public function run(
        ServerRequestInterface $request,
        ResponseInterface $response
    )
    {

        if ($this->running)
            throw new \RuntimeException(
                "Failed to run middleware queue: Queue is already running"
            );

        $this->running = true;
        $this->save();

        $next = function (
            ServerRequestInterface $request,
            ResponseInterface $response
        ) use (&$next) {

            if (count($this->middleware) > 0) {

                $middleware = array_shift($this->middleware);
                $response = call_user_func($middleware, $request, $response, $next);

                if (!($response instanceof ResponseInterface))
                    throw new \RuntimeException(
                        "Failed to run middleware: Middleware didn't return ".
                        "a valid ".ResponseInterface::class." object"
                    );
            }

            $this->running = false;
            $this->restore();
            return $response;
        };

        return $next($request, $response);
    }
532726
public function initialize(Server $server)
    {
        $this->server = $server;
        $server->on('method:GET', [$this, 'httpGet']);
        $server->on('method:OPTIONS', [$this, 'httpOptions']);
        $server->on('method:HEAD', [$this, 'httpHead']);
        $server->on('method:DELETE', [$this, 'httpDelete']);
        $server->on('method:PROPFIND', [$this, 'httpPropFind']);
        $server->on('method:PROPPATCH', [$this, 'httpPropPatch']);
        $server->on('method:PUT', [$this, 'httpPut']);
        $server->on('method:MKCOL', [$this, 'httpMkcol']);
        $server->on('method:MOVE', [$this, 'httpMove']);
        $server->on('method:COPY', [$this, 'httpCopy']);
        $server->on('method:REPORT', [$this, 'httpReport']);

        $server->on('propPatch', [$this, 'propPatchProtectedPropertyCheck'], 90);
        $server->on('propPatch', [$this, 'propPatchNodeUpdate'], 200);
        $server->on('propFind', [$this, 'propFind']);
        $server->on('propFind', [$this, 'propFindNode'], 120);
        $server->on('propFind', [$this, 'propFindLate'], 200);

        $server->on('exception', [$this, 'exception']);
    }
918064
function(response) {
        this.console.error('Server responded with error:');
        this.console.error('Status', response.statusCode);
        this.console.error('Headers', response.headers);
        response.on('data', function(chunk) {
            this.console.info('Body', chunk);
        }.bind(this));
        this._errCallback('server_error', response);
    }
386522
public function server(array $server)
    {
        foreach ((array) $server as $key => $value)
        {
            $string = strtolower(substr($key, 5));

            $key = str_replace('_', '-', $string);

            if (strpos($key, 'HTTP_') === 0)
            {
                $this->headers[$key] = $value;
            }
        }
    }
1108111
protected function errorResponse(ServerRequestInterface $request, ResponseInterface $response)
    {
        if (
            interface_exists(GlobalEnvironmentInterface::class, false) &&
            $response instanceof GlobalEnvironmentInterface &&
            $response->isStale()
        ) {
            $response = $response->revive();
        }

        $errorResponse = $response->withProtocolVersion($request->getProtocolVersion())->withStatus(500);
        $errorResponse->getBody()->write('An unexpected error occured');

        return $errorResponse;
    }
183851
public function request(ServerRequest $request = null)
    {
        $finding = $this->map->findByRequest($request = ($request ? : $this->request));

        return $this->run($finding);
    }
924038
public static function call(Server $server, $input)
    {
        $message = self::readMessage($input);

        if ($message === null) {
            return null;
        }

        /**
         * @var string
         */
        $method = $message->method;
        /**
         * @var \stdClass
         */
        $params = $message->params;

        $result = $server->call($method, $params);

        $response = new FromObject();
        $response->appendJson('result', $result);

        return self::createMessage($response->get());
    }
625803
public function register(
        ServerRequestInterface $request, ResponseInterface $response
    ) {
        $this->request = $request;
        $this->response = $response;
        return $this;
    }
856773
public function handleException(ServerRequestInterface $request, ResponseInterface $response, Exception $exception)
    {
        if ($level = $this->shouldLog('error')) {
            $this->logError($exception, $level);
        }

        return $this->handler->handleException($request, $response, $exception);
    }
1044984
public function run(ServerRequestInterface $request, ResponseInterface $response)
    {
        $route = $request->getAttribute('route');        
        $file = !empty($route->file) ? ltrim($route->file, '/') : '';

        if ($file[0] === '~' || strpos($file, '..') !== false) {
            trigger_error("Won't route to '$file': '~', '..' are not allowed in filename", E_USER_NOTICE);
            return $this->notFound($request, $response);
        }
        
        if (!file_exists($file)) {
            trigger_error("Failed to route using '$file': File doesn't exist", E_USER_NOTICE);
            return $this->notFound($request, $response);
        }

        $result = $this->includeScript($file, $request, $response);

        return $result === true || $result === 1 ? $response : $result;
    }