as json fix

This commit is contained in:
MeexReay 2024-11-30 01:37:07 +03:00
parent e281a87258
commit 6d3d1d1cbd
2 changed files with 7 additions and 7 deletions

View File

@ -44,11 +44,11 @@ impl HttpServer for EzSite {
if req.url.path == "/" { if req.url.path == "/" {
Some(HttpResponse::new( Some(HttpResponse::new(
OK, // response status code OK, // response status code
Headers::from(vec![ // response headers Headers::from(vec![ // response headers
("Content-Type", "text/html"), // - content type ("Content-Type", "text/html"), // - content type
("Content-Length", self.0.len().to_string().as_str()) // - content length ("Content-Length", self.0.len().to_string().as_str()) // - content length
]), Body::from_text(&self.0.clone()), // response body ]), Body::from_text(&self.0.clone()), // response body
)) ))
} else { } else {
None // close connection None // close connection
@ -56,7 +56,7 @@ impl HttpServer for EzSite {
} }
async fn on_start(&self, host: &str) { async fn on_start(&self, host: &str) {
println!("Http server started on {}", host); println!("Http server started on {host}");
} }
async fn on_close(&self) { async fn on_close(&self) {

View File

@ -39,7 +39,7 @@ impl Body {
} }
pub fn as_json(&self) -> Option<Value> { pub fn as_json(&self) -> Option<Value> {
serde_json::to_value(self.as_text()?).ok() serde_json::from_str(&self.as_text()?).ok()
} }
pub fn from_bytes(bytes: &[u8]) -> Body { pub fn from_bytes(bytes: &[u8]) -> Body {