public function render(bool $emulate = false)
    {
        $response = $this->getResponse();

        if (!$this->prepare()) {
            return $this;
        }

        if ($response->getStatus() == 200 && !$this->process()) {
            return $this;
        }

        $continue = true;

        //check for content
        //check for redirect
        if (!$response->hasContent()
            && !$response->hasJson()
            && !$this->hasRedirect()
        ) {
            $request = $this->getRequest();
            $response->setStatus(404, HttpHandler::STATUS_404);

            $error = new HttpException(HttpHandler::STATUS_404, 404);

            $continue = $this->getErrorProcessor()->process($request, $response, $error);
        }

        if ($continue) {
            $this->getDispatcher()->dispatch($response, $emulate);
        }

        //the connection is already closed
        //also remember there are no more sessions
        $this->shutdown();

        return $this;
    }