From cc2661d8ac8b9570bc4bf57767669e1757b686a1 Mon Sep 17 00:00:00 2001 From: midefos Date: Thu, 23 Jan 2025 17:14:37 +0100 Subject: [PATCH] adding method to extract separately string, instead of parse --- src/requester.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/requester.rs b/src/requester.rs index 22b30ee..a92d07d 100644 --- a/src/requester.rs +++ b/src/requester.rs @@ -2,21 +2,23 @@ use http::Request; use http_body_util::BodyExt; use hyper::body::Incoming; use serde::de::DeserializeOwned; -use std::{any::TypeId, error::Error}; +use std::error::Error; pub struct Requester; impl Requester { pub async fn extract_body(req: Request) -> Result> where - T: DeserializeOwned + 'static, + T: DeserializeOwned, { let body = req.collect().await?.to_bytes(); - if TypeId::of::() == TypeId::of::() { - let string = String::from_utf8(body.to_vec())?; - return Ok(serde_json::from_str(&string)?); - } - Ok(serde_json::from_slice(&body)?) } + + pub async fn extract_body_str( + req: Request, + ) -> Result> { + let body = req.collect().await?.to_bytes(); + Ok(String::from_utf8_lossy(&body).to_string()) + } }