Warp: Convert hyper::Body to a String?

Hi there,

I'm trying to glue together oxide-auth and warp and I'm trying to convert an impl warp::reply::Reply to a oxide_auth::frontends::simple::request::Response

I'm facing multiple issues, but the one for this question is that I want to convert the hyper::Body that is in http::Response into a String so I can put it as body in the oxide-auth's response object.

I've seen the use of hyper::body::to_bytes but it's async and I'm in the From::from() implementation which is not async…

How can I get a String out of an hyper::Body easily?

You can't do it in a From impl, because the entire body might not have been received yet.

First, thank you again for your answer, @alice :slight_smile:

In my case, it is, because the warp::Response is the one I built to be sent. I guess I have to do a method in my wrapper (which has lifetime issue as well) to do the conversion then.

pub struct OAuthResponse {
    inner: Box<dyn Reply>,
}

impl OAuthResponse {
    pub fn new(rep: impl Reply) -> Self {
        OAuthResponse {
            inner: Box::new(rep),
        }
    }

    pub fn into_inner(self) -> Box<dyn Reply> {
        self.inner
    }
}

I don't really know anything about warp, but surely it allows you to provide a body that provides data in an async way, and not everything all at once.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.