How do I read the entire body of a Tokio-based Hyper request?

后端 未结 3 1792
粉色の甜心
粉色の甜心 2020-11-28 15:07

I want to write a server using the current master branch of Hyper that saves a message that is delivered by a POST request and sends this message to every incoming GET reque

3条回答
  •  旧时难觅i
    2020-11-28 15:46

    Hyper 0.13 provides a body::to_bytes function for this purpose.

    use hyper::body;
    use hyper::{Body, Response};
    
    pub async fn read_response_body(res: Response) -> Result {
        let bytes = body::to_bytes(res.into_body()).await?;
        Ok(String::from_utf8(bytes.to_vec()).expect("response was not valid utf-8"))
    }
    

提交回复
热议问题