New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to correcly use body::stream()
#448
Comments
What does your code look like? Without looking, you could probably get this to work using |
The nearest I seem to have got to it working is with the following code fn proxy(
client: HttpClient,
) -> impl Filter<Extract = impl warp::Reply, Error = warp::Rejection> + Clone {
path_and_query()
.and(warp::method())
.and(header::headers_cloned())
.and(warp::body::stream())
.and(with_client(client))
.and_then(handlers::proxy_request)
} async fn proxy_request(
url: url::Url,
method: Method,
headers: HeaderMap,
body: impl Stream<Item = Result<impl Buf, warp::Error>> + Send + Sync,
client: hyper::Client<hyper_rustls::HttpsConnector<hyper::client::HttpConnector>>,
) -> Result<impl warp::Reply, warp::Rejection> {
let mut request = hyper::Request::builder()
.uri(url.as_str())
.method(method)
.body(hyper::Body::wrap_stream(body))
.unwrap();
*request.headers_mut() = headers;
let response = client.request(request).await;
Ok(response.unwrap()) This is what gives me the above error. The aim is ultimately to pass the body around as efficiently as possible to avoid allocating a lot of memory if the body is large. |
If you add let body = body.map_ok(|mut buf| {
buf.to_bytes()
}); |
Thanks, doing that and adding |
I am trying to do almost exactly what was asked in #139; take the request as is, forward it to another host using
hyper::Client
and then return the response straight back to the client. I thought I had hit the jackpot when I found that issue but it seems that since thenBodyStream
has been made private in #345.I am struggling to figure out how to take the stream returned by
body::stream()
and create my new response from it. When I try to usewrap_stream
it complains thatInto<Bytes>
, which is required bywrap_stream
is not satisfied forimpl Buf
If I make
BodyStream
public again I can get this working fine. I am fairly new to rust, am I doing something wrong here or shouldBodyStream
be exported for this to work?The text was updated successfully, but these errors were encountered: