From 6d3d1d1cbd84c43af1734b238690f25ab6fc6b87 Mon Sep 17 00:00:00 2001 From: MeexReay Date: Sat, 30 Nov 2024 01:37:07 +0300 Subject: [PATCH] as json fix --- README.md | 12 ++++++------ src/ezhttp/body.rs | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 37bf3ef..842ea7e 100644 --- a/README.md +++ b/README.md @@ -44,11 +44,11 @@ impl HttpServer for EzSite { if req.url.path == "/" { Some(HttpResponse::new( - OK, // response status code - Headers::from(vec![ // response headers - ("Content-Type", "text/html"), // - content type - ("Content-Length", self.0.len().to_string().as_str()) // - content length - ]), Body::from_text(&self.0.clone()), // response body + OK, // response status code + Headers::from(vec![ // response headers + ("Content-Type", "text/html"), // - content type + ("Content-Length", self.0.len().to_string().as_str()) // - content length + ]), Body::from_text(&self.0.clone()), // response body )) } else { None // close connection @@ -56,7 +56,7 @@ impl HttpServer for EzSite { } async fn on_start(&self, host: &str) { - println!("Http server started on {}", host); + println!("Http server started on {host}"); } async fn on_close(&self) { diff --git a/src/ezhttp/body.rs b/src/ezhttp/body.rs index 646385b..f2e454c 100644 --- a/src/ezhttp/body.rs +++ b/src/ezhttp/body.rs @@ -39,7 +39,7 @@ impl Body { } pub fn as_json(&self) -> Option { - serde_json::to_value(self.as_text()?).ok() + serde_json::from_str(&self.as_text()?).ok() } pub fn from_bytes(bytes: &[u8]) -> Body {