From ecdb6c7db16406a20b56e7bb6e73d4c59ee246f1 Mon Sep 17 00:00:00 2001 From: Vika Date: Thu, 21 Jul 2022 13:03:37 +0300 Subject: media: improve Metadata typing content_type is now optional; if not specified, it will remain empty. `application/octet-stream` will be put on read in the frontend. Length is now represented as NonZeroUsize - why would you upload a zero-byte file when you can just conjure one from the void whenever you need one? This should save me a little bit of memory. Representing content_type as a typed MIME value would be the next logical step. --- kittybox-rs/src/media/mod.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'kittybox-rs/src/media/mod.rs') diff --git a/kittybox-rs/src/media/mod.rs b/kittybox-rs/src/media/mod.rs index b64929d..a8ae6f9 100644 --- a/kittybox-rs/src/media/mod.rs +++ b/kittybox-rs/src/media/mod.rs @@ -76,7 +76,11 @@ pub async fn serve( let headers = r.headers_mut().unwrap(); headers.insert( "Content-Type", - HeaderValue::from_str(&metadata.content_type).unwrap() + HeaderValue::from_str( + metadata.content_type + .as_deref() + .unwrap_or("application/octet-stream") + ).unwrap() ); if let Some(length) = metadata.length { headers.insert( -- cgit 1.4.1