diff options
author | Martin Dørum <martid0311@gmail.com> | 2020-05-19 10:46:09 -0400 |
---|---|---|
committer | Martin Dørum <martid0311@gmail.com> | 2020-05-19 10:46:09 -0400 |
commit | 5138884121ceb345cd4bbe6038bf48a00272ebab (patch) | |
tree | a41fbb994b553aa69a213703ad03f8e8a731968e /src/main.rs | |
parent | f87acd79878da04e3ecec23c4e83c688e28a3f75 (diff) |
send no Content-Type header when we don't know
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/src/main.rs b/src/main.rs index a1aed23..32c012a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -110,11 +110,8 @@ async fn on_get(req: Request<Body>) -> Result<Response<Body>, Infallible> { // If we have an extension, we need to serve with the appropriate Content-Type let mime = match &Path::new(path).extension() { - Some(ext) => match mime_guess::from_ext(&ext.to_string_lossy()).first_raw() { - Some(mime) => mime, - None => "text/plain", - }, - None => "text/plain", + Some(ext) => mime_guess::from_ext(&ext.to_string_lossy()).first_raw(), + None => None, }; let mut pathbuf = Path::new(&CONFIG.data as &str).join(&name); @@ -131,9 +128,11 @@ async fn on_get(req: Request<Body>) -> Result<Response<Body>, Infallible> { let body = Body::wrap_stream(stream); let mut resp = Response::new(body); - resp.headers_mut().insert( - "Content-Type", - HeaderValue::from_str(&mime).unwrap()); + if let Some(mime) = mime { + resp.headers_mut().insert( + "Content-Type", + HeaderValue::from_str(&mime).unwrap()); + } if let Ok(meta) = meta { resp.headers_mut().insert( |