Comments (7)
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.
@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.
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.
Master now has changes to allow any Response<impl Into<hyper::Body>>
!
from warp.
That was quick, thank you!
from warp.
@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.
@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)
- Clarify API docs around multipart forms HOT 2
- Feature request: More customization points in tracing HOT 2
- EC Private key support HOT 1
- Make `Option<F>` a filter when F is a filter
- Feature request: `warp::make_service()` or `warp::service_with_addr()`
- CVE-2023-43669/GHSA-9mcr-873m-xcxp: tungstenite <= 0.20.0 DoS vulnerability HOT 1
- [feature request] [low prio] Non-Metal fallback option HOT 2
- SSE gives up on Streams that return Pending HOT 3
- Server::run should return ! (never type)
- Default OS / self signed certificate without create it HOT 1
- websocket disconnect (code: 1006, reason: "") HOT 2
- Add `rust-version` into `Cargo.toml` HOT 1
- Error `connection closed before message completed` after 60s HOT 2
- Websocket connection closes immediately, but not with firefox HOT 4
- Navigation between panes using vim commands HOT 1
- examples/tls/cert.pem has expired
- Upgrade to hyper v1 HOT 4
- key contains no private key while using ecc key HOT 1
- integrate with monoio
- HELP: filters inside .then never get executed HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from warp.