private function filterResponse(Response $response, Request $request, int $type): string
    {
        $event = new FilterResponseEvent($this->kernel, $request, $type, $response);
        $this->dispatcher->dispatch(KernelEvents::RESPONSE, $event);
        $this->dispatcher->dispatch(KernelEvents::FINISH_REQUEST, new FinishRequestEvent($this->kernel, $request, $type));

        $request->attributes->remove('data');
        $request->attributes->set('_controller', 'typo3');

        $response = $event->getResponse();

        if ($response instanceof RedirectResponse) {
            $response->send();
            $this->kernel->terminate($request, $response);

            exit();
        }

        if (\count($response->headers) || 200 !== $response->getStatusCode()) {
            $response->sendHeaders();
        }

        return $response->getContent();
    }