From 2d91b34cecdbbf3a5f293aa8f9900ebbc6096e61 Mon Sep 17 00:00:00 2001 From: Claudio Cicconetti Date: Mon, 11 Sep 2023 10:10:31 +0200 Subject: [PATCH] Simple workflow: make http_read_number more readable --- .../http_read_number/src/lib.rs | 38 ++++++------------- 1 file changed, 12 insertions(+), 26 deletions(-) diff --git a/examples/simple_workflow_http/http_read_number/src/lib.rs b/examples/simple_workflow_http/http_read_number/src/lib.rs index b769a993..96d1e6e8 100644 --- a/examples/simple_workflow_http/http_read_number/src/lib.rs +++ b/examples/simple_workflow_http/http_read_number/src/lib.rs @@ -10,43 +10,29 @@ impl Edgefunction for HttpReadNumberFun { log::info!("http_read_number: 'Call' called, MSG: {}", encoded_message); let req: EdgelessHTTPRequest = edgeless_http::request_from_string(&encoded_message).unwrap(); - let res = if req.path == "/read_number" { + let res_params = if req.path == "/read_number" { if let Some(body) = req.body { if let Ok(content) = String::from_utf8(body) { if let Ok(_) = content.parse::() { cast_alias("cb_success", &content); - EdgelessHTTPResponse { - status: 200, - body: None, - headers: std::collections::HashMap::::new(), - } + (200, None) } else { - EdgelessHTTPResponse { - status: 400, - body: Some(Vec::::from("body does not contain an integer")), - headers: std::collections::HashMap::::new(), - } + (400, Some(Vec::::from("body does not contain an integer"))) } } else { - EdgelessHTTPResponse { - status: 400, - body: Some(Vec::::from("body is not a string")), - headers: std::collections::HashMap::::new(), - } + (400, Some(Vec::::from("body is not a string"))) } } else { - EdgelessHTTPResponse { - status: 400, - body: Some(Vec::::from("empty body")), - headers: std::collections::HashMap::::new(), - } + (400, Some(Vec::::from("empty body"))) } } else { - EdgelessHTTPResponse { - status: 404, - body: Some(Vec::::from("invalid path")), - headers: std::collections::HashMap::::new(), - } + (404, Some(Vec::::from("invalid path"))) + }; + + let res = EdgelessHTTPResponse { + status: res_params.0, + body: res_params.1, + headers: std::collections::HashMap::::new(), }; CallRet::Reply(edgeless_http::response_to_string(&res))