Coder Social home page Coder Social logo

Reply with a stream about warp HOT 7 CLOSED

seanmonstar avatar seanmonstar commented on May 4, 2024
Reply with a stream

from warp.

Comments (7)

darkprokoba avatar darkprokoba commented on May 4, 2024 10

Of course if there is a better way to forward the reqwest response, a hint would be much appreciated :)

This seems to work for me:

async fn proxy(_unused: String) -> Result<impl warp::Reply, Infallible> {
    let response_stream =
        reqwest::get("http://build/builds/file.tar.bz2").await.unwrap().bytes_stream();
    let body= hyper::Body::wrap_stream(response_stream);
    Ok(warp::reply::Response::new(body))
}

from warp.

tp avatar tp commented on May 4, 2024 2

@seanmonstar Was this reverted? The following code doesn't work for me, even though I explicitly create a hyper::Body:

async fn get_x() -> Result<impl warp::Reply, std::convert::Infallible> {
    let response_stream = reqwest::get("....").await.unwrap().bytes_stream();
    let body: hyper::Body = hyper::Body::wrap_stream(response_stream);
    Ok(body)
}

errs with

the trait `warp::reply::Reply` is not implemented for `hyper::body::body::Body`

Of course if there is a better way to forward the reqwest response, a hint would be much appreciated :)

from warp.

seanmonstar avatar seanmonstar commented on May 4, 2024

My original concern was that I didn't want to expose exactly how streaming responses works, in case adding compression filters needed to adjust them, and thus create a breaking change. However, I think warp can also implement Reply for response with a hyper::Body, and if the internal type needs to change, that specific impl can simply map it...

from warp.

seanmonstar avatar seanmonstar commented on May 4, 2024

Master now has changes to allow any Response<impl Into<hyper::Body>>!

from warp.

sorin-davidoi avatar sorin-davidoi commented on May 4, 2024

That was quick, thank you!

from warp.

seanmonstar avatar seanmonstar commented on May 4, 2024

@tp I don't think this was reverted... a guess, do the versions match? If the version of hyper you're using doesn't match the version warp is, then the trait won't be implemented. (If it doesn't work, let's open a new issue to track, as it'd be a new bug.)

from warp.

rahulmr avatar rahulmr commented on May 4, 2024

@darkprokoba I have a similar requirement. Could you please help?

I want to create a similar proxy kind of setup.
But before the get request, I want to add header information to it.

Also, want to work on post reqwest, how to pass the received post request json body to the external url?

from warp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.