The question is related to this question. However, I’ll better start a new topic, since the question is slightly different.
Like @thejefflarson I also would have needed to create a Body from a Stream of Chunks. The context is the following:
- receive requst as server
- do something to the body
- forward the request as client to another destination
(i.e., some kind of proxy behaviour)
It would be pretty easy to simply use
Requst<Box<Stream<Item=Chunk, Error=hyper::Error> as not having to deal with the problem that
Body does not offer a corresponding
From trait implementation.
Client is only implemented for
Client<HttpConnector, Body>, hence I’m forced to rely on
Body as body type.
This feels unsatisfactory. So there are two fundamental questions here (which are both related to resolving the issue):
- Why can’t a Body be build out of a Stream, especially a Stream of Chunks? It seems natural to have such an implementation, since a Body is a Stream of Chunks. Is there some reason why it can’t be provided? This is probably tokio-proto related, since the Body implementation in hyper is just a thin wrapper around the tokio-proto Body. The workaround (suggested here) with using a channel internally for (re-)creating the body works, but is somehow ugly…
- Why is a Client forced to use
Bodyas Request Body? I suppose it’s using the same encoding/decoding infrastructur as sending and receiving in the Server? Maybe I’m missing something… can someone give me some pointers?
EDIT: type can be adjusted via the client’s