public function beforeRender(Event $event)
    {
        /** @var \Cake\Controller\Controller $controller */
        $controller = $event->getSubject();
        $response = $controller->getResponse();
        $request = $controller->getRequest();

        if ($this->ext && !in_array($this->ext, ['html', 'htm'])) {
            if (!$response->getMimeType($this->ext)) {
                throw new NotFoundException('Invoked extension not recognized/configured: ' . $this->ext);
            }

            $this->renderAs($controller, $this->ext);
            $response = $controller->response;
        } else {
            $response = $response->withCharset(Configure::read('App.encoding'));
        }

        if ($this->_config['checkHttpCache'] &&
            $response->checkNotModified($request)
        ) {
            $controller->setResponse($response);

            return false;
        }
        $controller->setResponse($response);
    }