-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Allow hyper::Body to be created from Read or AsyncRead #1328
Comments
Hi @cetra3! When building a response, you are not forced to use To get from a As an example: // initialise fs pool somewhere in your server
let pool = futures_fs::FsPool::default();
// later, in a request handler
let file_read_stream = pool.read("example.txt");
let response = hyper::Response::new().with_body(file_read_stream); |
@seanmonstar should we add this to the guide? |
Sorry, didn't write here as the user also asked on Reddit, and got several answers. The guide does try to touch on the stream being able to be changed, but it might not be that obvious. Probably the guide should be more properly designed, instead of the sort of mishmash I've put together so far... |
I use a Stream to construct a Request like this.
And I can not compile it, the error is
How to fix it? thank you! |
@xinghun92 Try explicitly creating a let mut request: ::hyper::Request<FsReadStream> = ::hyper::Request::new(::hyper::Method::Post, ::hyper::Uri::from_str("http://www.google.com").unwrap());
let pool = FsPool::default();
let file_read_stream = pool.read("test.txt");
request.set_body(file_read_stream); |
It fails when send this request using client.
The error is
|
Hmm, seems like this is starting to become more tricky. Your current problem would be solved by using @seanmonstar Can you think of anything that might make this easier? For instance, could we change I'm thinking something like impl<B> Config<UseDefaultConnector, B>
where B: Stream,
B::Item: AsRef<[u8]>,
B::Error: Into<Error>,
{
...
}
impl<C, B> Client<C, B>
where
C: Connect,
B: Stream + 'static,
B::Item: AsRef<[u8]>,
B::Error: Into<Error>,
{
...
} |
Having |
@srijs I'm using the shio-rs framework that requires a I've implemented a workaround using the So it is possible to still use hyper::Body with a file stream which is good, but the ergonomics around it is pretty bad. |
@cetra3 Could you open an issue on Shio? We should generalize and support this. |
I'd like to be able to construct a response from a static File or a Read interface. Not sure if this is already possible.
I.e,
The text was updated successfully, but these errors were encountered: