public function respondAs($type, array $options = [])
    {
        $defaults = ['index' => null, 'charset' => null, 'attachment' => false];
        $options += $defaults;

        $cType = $type;
        $controller = $this->getController();
        $response = $controller->getResponse();
        $request = $controller->getRequest();

        if (strpos($type, '/') === false) {
            $cType = $response->getMimeType($type);
        }
        if (is_array($cType)) {
            if (isset($cType[$options['index']])) {
                $cType = $cType[$options['index']];
            }

            if ($this->prefers($cType)) {
                $cType = $this->prefers($cType);
            } else {
                $cType = $cType[0];
            }
        }

        if (!$type) {
            return false;
        }
        if (!$request->getParam('requested')) {
            $response = $response->withType($cType);
        }
        if (!empty($options['charset'])) {
            $response = $response->withCharset($options['charset']);
        }
        if (!empty($options['attachment'])) {
            $response = $response->withDownload($options['attachment']);
        }
        $controller->setResponse($response);

        return true;
    }