public function emitResponse(ServerRequestInterface $request, ResponseInterface $response)
    {
        try {
            $this->getResponseEmitter()->emit($response);
        } catch (\Exception $e) {
            if ($this->canForceResponseEmitting()) {
                // flush buffers
                $maxBufferLevel = ob_get_level();

                while (ob_get_level() > $maxBufferLevel) {
                    ob_end_flush();
                }

                // print response
                echo $response->getBody();
            } else {
                throw $e;
            }
        }
        $applicationEvent = $this->getApplicationEvent();
        $applicationEvent->setName(self::EVENT_RESPONSE_SENT);
        $applicationEvent->setRequest($request);
        $applicationEvent->setResponse($response);
        $this->emit($applicationEvent);
    }