From c87239f9c101b9e2689131531315f2a63fdfcde7 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Wed, 30 Mar 2022 21:57:52 +0100 Subject: [PATCH] actix Files: change error handling for middleware fixup fn Signed-off-by: Ian Jackson --- daemon/main.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/daemon/main.rs b/daemon/main.rs index 70b6ff1b..e0389eba 100644 --- a/daemon/main.rs +++ b/daemon/main.rs @@ -374,7 +374,17 @@ async fn r_bundle(path: Path<( .set_content_type(ctype.into_mime()) } -#[throws(actix_web::Error)] +#[derive(Error)] +#[error("actix Files produced improper response: {0}")] +#[derive(Debug, Clone, From)] +pub struct FilesImproperResponse(String); + +impl ResponseError for FilesImproperResponse { + fn status_code(&self) -> StatusCode { StatusCode::INTERNAL_SERVER_ERROR } + fn error_response(&self) -> HttpResponse { error_response(self) } +} + +#[throws(FilesImproperResponse)] fn src_ct_fixup(resp: ServiceResponse) -> ServiceResponse { resp } @@ -529,7 +539,7 @@ async fn main() -> Result<(),StartupError> { .add((header::REFERRER_POLICY, "no-referrer")) ) .wrap_fn(|req, svc| { - svc.call(req).map(|resp| resp.and_then(src_ct_fixup)) + svc.call(req).map(|resp| Ok(src_ct_fixup(resp?)?)) }) .wrap(middleware::Logger::default()) ; -- 2.30.2