From 1d0223a40772b16a04249c84ee180e23789cfcdb Mon Sep 17 00:00:00 2001 From: alemi Date: Fri, 21 Oct 2022 02:48:24 +0200 Subject: [PATCH] feat: return pretty json in responses --- Cargo.toml | 2 +- src/main.rs | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 5183165..f0143d5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "http-debugger" -version = "0.2.2" +version = "0.2.3" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/src/main.rs b/src/main.rs index 275136e..f42079d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -76,15 +76,16 @@ async fn echo_json(mut req: Request) -> Result, hyper::http time: SystemTime::now().duration_since(UNIX_EPOCH).unwrap_or(Duration::from_secs(0)).as_secs_f64(), }; - let serialized = serde_json::to_string(&inspect).unwrap_or("[]".to_string()); + let serialized_mini = serde_json::to_string(&inspect).unwrap_or("[]".to_string()); + let serialized_pretty = serde_json::to_string_pretty(&inspect).unwrap_or("[]".to_string()); // println!(" * {}", serde_json::to_string_pretty(&response)?); - println!(" * {}", serialized); + println!(" * {}", serialized_mini); Response::builder() .status(StatusCode::OK) .header("Content-Type", "application/json") - .body(serialized.into()) + .body(serialized_pretty.into()) } #[tokio::main]