From b62900f6f4478d0a64e0b371f967f50950b70de0 Mon Sep 17 00:00:00 2001 From: Andrew Straw Date: Sat, 23 Dec 2023 15:03:23 +0100 Subject: [PATCH] fix DRY violation --- src/lowlevel.rs | 44 ++++++++++++++------------------------------ 1 file changed, 14 insertions(+), 30 deletions(-) diff --git a/src/lowlevel.rs b/src/lowlevel.rs index f3121c6..3844837 100644 --- a/src/lowlevel.rs +++ b/src/lowlevel.rs @@ -587,21 +587,21 @@ where res_session_key, req ); - if req.method() == Method::POST && req.uri().path() == "/callback" { - let login_info = match res_session_key { - Ok(login_info) => login_info, - Err(errors) => { - warn!("no (valid) session key in callback"); - let body_buf = serde_json::to_vec(&errors).unwrap(); - let resp = http::Response::builder() - .header(hyper::header::CONTENT_TYPE, JSON_TYPE) - .status(StatusCode::BAD_REQUEST) - .body(body_from_buf(&body_buf)) - .expect("response"); - return Box::pin(std::future::ready(Ok(resp))); - } - }; + let login_info = match res_session_key { + Ok(login_info) => login_info, + Err(errors) => { + warn!("no (valid) session key in request"); + let body_buf = serde_json::to_vec(&errors).unwrap(); + let resp = http::Response::builder() + .header(hyper::header::CONTENT_TYPE, JSON_TYPE) + .status(StatusCode::BAD_REQUEST) + .body(body_from_buf(&body_buf)) + .expect("response"); + return Box::pin(std::future::ready(Ok(resp))); + } + }; + if req.method() == Method::POST && req.uri().path() == "/callback" { let mut resp0 = http::Response::builder(); let session_key = match login_info { ValidLogin::NeedsSessionKey => { @@ -622,22 +622,6 @@ where let resp = http::Response::builder(); - let login_info = match res_session_key { - Ok(login_info) => login_info, - Err(_errors) => { - let estr = "No (valid) token in request.".to_string(); - let errors = ErrorsBackToBrowser { errors: vec![estr] }; - - let body_buf = serde_json::to_vec(&errors).unwrap(); - let resp = http::Response::builder() - .header(hyper::header::CONTENT_TYPE, JSON_TYPE) - .status(StatusCode::BAD_REQUEST) - .body(body_from_buf(&body_buf)) - .expect("response"); - return Box::pin(std::future::ready(Ok(resp))); - } - }; - use futures::future::FutureExt; let resp_final = handle_req( self.clone(),