* @template-extends Response> */ class DownloadResponse extends Response { /** * Creates a response that prompts the user to download the file * @param string $filename the name that the downloaded file should have * @param C $contentType the mimetype that the downloaded file should have * @param S $status * @param H $headers * @since 7.0.0 */ public function __construct(string $filename, string $contentType, int $status = Http::STATUS_OK, array $headers = []) { parent::__construct($status, $headers); $sanitized = str_replace(['/', '\\'], '-', $filename); $fallback = str_replace('%', '', (new UnicodeString($sanitized))->ascii()->toString()); $this->addHeader('Content-Disposition', HeaderUtils::makeDisposition(HeaderUtils::DISPOSITION_ATTACHMENT, $sanitized, $fallback)); $this->addHeader('Content-Type', $contentType); } }