protected function filterResponse(Response $response, Request $request, $type)
{
if ($this->eventDispatcher !== null) {
$event = new FilterResponseEvent($this, $request, $type, $response);
$this->eventDispatcher->dispatch(KernelEvents::RESPONSE, $event);
$response = $event->getResponse();
}
$response->prepare($request);
$this->finishRequest($request, $type);
return $response;
}