From 27bb803ad35329cf414ebb6409ad652b9fe65d32 Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" Date: Thu, 5 Mar 2020 16:57:26 -0500 Subject: [PATCH] fix: Return HTTP No Content on successful write The `inch` tool expects status code 204 instead of 200, so actually send no content instead of empty JSON. --- src/main.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index d2be058ae7..89c785cf4e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -42,7 +42,7 @@ struct WriteInfo { bucket_name: String, } -async fn write(req: hyper::Request, app: Arc) -> Result { +async fn write(req: hyper::Request, app: Arc) -> Result, ApplicationError> { let query = req.uri().query().ok_or(StatusCode::BAD_REQUEST)?; let write_info: WriteInfo = serde_urlencoded::from_str(query).map_err(|_| StatusCode::BAD_REQUEST)?; @@ -89,7 +89,7 @@ async fn write(req: hyper::Request, app: Arc) -> Result, app: Arc) -> Result { +async fn read(req: hyper::Request, app: Arc) -> Result, ApplicationError> { let query = req .uri() .query() @@ -215,7 +215,7 @@ async fn read(req: hyper::Request, app: Arc) -> Result, app: Arc) -> http::Result> { @@ -229,9 +229,13 @@ async fn service(req: hyper::Request, app: Arc) -> http::Result Ok(hyper::Response::builder() + Ok(Some(body)) => Ok(hyper::Response::builder() .body(body) .expect("Should have been able to construct a response")), + Ok(None) => Ok(hyper::Response::builder() + .status(StatusCode::NO_CONTENT) + .body(Body::empty()) + .expect("Should have been able to construct a response")), Err(e) => { let json = serde_json::json!({"error": e.to_string()}).to_string(); Ok(hyper::Response::builder()