From d9c92a282720619f3c25b3213051d44d3b200431 Mon Sep 17 00:00:00 2001 From: neri Date: Sat, 23 Apr 2022 23:40:35 +0200 Subject: [PATCH] use html view even if content matches text/html --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/download.rs | 14 +++++++------- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 30bf4e7..917a80b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -434,7 +434,7 @@ dependencies = [ [[package]] name = "datatrash" -version = "1.1.0" +version = "1.1.1" dependencies = [ "actix-files", "actix-multipart", diff --git a/Cargo.toml b/Cargo.toml index a3a966e..90fd015 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "datatrash" -version = "1.1.0" +version = "1.1.1" authors = ["neri"] edition = "2021" diff --git a/src/download.rs b/src/download.rs index 4f3f09b..4e6ba95 100644 --- a/src/download.rs +++ b/src/download.rs @@ -91,6 +91,9 @@ async fn get_view_type( if delete_on_download || req.query_string().contains("dl") { return ViewType::Download; } + if req.query_string().contains("raw") { + return ViewType::Raw; + } let is_text = FileKind::from_str(file_kind) == Ok(FileKind::Text) || file_mime.type_() == mime::TEXT; if !is_text { @@ -101,18 +104,15 @@ async fn get_view_type( } if let Ok(accept) = Accept::parse(req) { for accept_mime in accept.ranked() { - if mime_matches(&accept_mime, file_mime) { - return ViewType::Raw; - } if accept_mime == TEXT_HTML { + return ViewType::Html; + } + if mime_matches(&accept_mime, file_mime) { break; } } - } else { - return ViewType::Raw; } - - ViewType::Html + ViewType::Raw } fn mime_matches(accept: &Mime, content: &Mime) -> bool {