Skip to content

Commit 99f0a00

Browse files
committed
automatically add extension to filename in csv component when needed
1 parent 06e8e71 commit 99f0a00

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/render.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,10 +231,13 @@ impl HeaderContext {
231231
async fn csv(mut self, options: &JsonValue) -> anyhow::Result<PageContext> {
232232
self.response
233233
.insert_header((header::CONTENT_TYPE, "text/csv; charset=utf-8"));
234-
if let Some(filename) = get_object_str(options, "filename") {
234+
if let Some(filename) =
235+
get_object_str(options, "filename").or_else(|| get_object_str(options, "title"))
236+
{
237+
let extension = if filename.contains('.') { "" } else { ".csv" };
235238
self.response.insert_header((
236239
header::CONTENT_DISPOSITION,
237-
format!("attachment; filename={filename}"),
240+
format!("attachment; filename={filename}{extension}"),
238241
));
239242
}
240243
let csv_renderer = CsvBodyRenderer::new(self.writer, options).await?;

0 commit comments

Comments
 (0)