aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Fischer <martin@push-f.com>2021-07-04 22:38:15 +0200
committerMartin Fischer <martin@push-f.com>2021-07-04 22:38:15 +0200
commit062806515ae16af083b1e5a47fba950837f0a410 (patch)
treebad90fbb5252539eadf66b03ec07460385ea3526
parenta803509255ce1f5edc6e77e9e483a721978e9b83 (diff)
refactor: short-circuit with ? instead of mapping
-rw-r--r--src/get_routes.rs50
1 files changed, 24 insertions, 26 deletions
diff --git a/src/get_routes.rs b/src/get_routes.rs
index cde88c3..be2e9c4 100644
--- a/src/get_routes.rs
+++ b/src/get_routes.rs
@@ -340,20 +340,19 @@ fn raw_blob<C: Controller>(
ctx: Context,
parts: &Parts,
) -> Result<HyperResponse, Error> {
- build_raw_response(entr, &ctx, parts).map(|mut resp| {
- if let Some(mime) = mime_guess::from_path(&ctx.path).first() {
- if mime.type_() == "text" {
- // workaround for Firefox, which downloads non-plain text subtypes
- // instead of displaying them (https://bugzilla.mozilla.org/1319262)
- resp.headers_mut()
- .insert(header::CONTENT_TYPE, "text/plain".parse().unwrap());
- } else {
- resp.headers_mut()
- .insert(header::CONTENT_TYPE, mime.to_string().parse().unwrap());
- }
+ let mut resp = build_raw_response(entr, &ctx, parts)?;
+ if let Some(mime) = mime_guess::from_path(&ctx.path).first() {
+ if mime.type_() == "text" {
+ // workaround for Firefox, which downloads non-plain text subtypes
+ // instead of displaying them (https://bugzilla.mozilla.org/1319262)
+ resp.headers_mut()
+ .insert(header::CONTENT_TYPE, "text/plain".parse().unwrap());
+ } else {
+ resp.headers_mut()
+ .insert(header::CONTENT_TYPE, mime.to_string().parse().unwrap());
}
- resp
- })
+ }
+ Ok(resp)
}
fn run_blob<C: Controller>(
@@ -368,19 +367,18 @@ fn run_blob<C: Controller>(
"run action only available for .html files".into(),
));
}
- build_raw_response(entr, &ctx, parts).map(|mut resp| {
- resp.headers_mut()
- .insert(header::CONTENT_TYPE, "text/html".parse().unwrap());
- // We want users to be able to view .html applications of other users
- // without having to worry about the application accessing their private
- // files. So we set the CSP: sandbox header which makes browsers treat
- // the page as a unique origin as per the same-origin policy.
- resp.headers_mut().insert(
- header::CONTENT_SECURITY_POLICY,
- "sandbox allow-scripts;".parse().unwrap(),
- );
- resp
- })
+ let mut resp = build_raw_response(entr, &ctx, parts)?;
+ resp.headers_mut()
+ .insert(header::CONTENT_TYPE, "text/html".parse().unwrap());
+ // We want users to be able to view .html applications of other users
+ // without having to worry about the application accessing their private
+ // files. So we set the CSP: sandbox header which makes browsers treat
+ // the page as a unique origin as per the same-origin policy.
+ resp.headers_mut().insert(
+ header::CONTENT_SECURITY_POLICY,
+ "sandbox allow-scripts;".parse().unwrap(),
+ );
+ Ok(resp)
}
fn move_blob<C: Controller>(