http-rs / tide

Fast and friendly HTTP server framework for async Rust
https://docs.rs/tide
Apache License 2.0
5.07k stars 321 forks source link

Rewrite Multipart support using `multipart-async` #89

Open abonander opened 6 years ago

abonander commented 6 years ago

@liufuyang did an excellent job implementing the current multipart support and I'm flattered he chose my crate, but I'm worried about the scalability of collecting the entire request body to Vec<u8>, as you typically don't want to keep whole files in memory.

I have multipart-async which is designed to parse a multipart body from an async stream but it has languished a bit as I was waiting for the futures churn to settle and then I kind of forgot about it.

I'll be coming back to it and fixing it up, and I'd be glad to consult on/mentor a refactoring of Tide's multipart support to use it, or even another crate if there is one.

liufuyang commented 6 years ago

Thank you @abonander. I would like to provide some help refactoring it when it is ready (Especially if you or someone can mentoring me 😄)

alexesmet commented 3 years ago

Is there a possibility to use @abonander's multipart-async with current (v0.16.0) version of tide to parse multipart body of a request?

The main obstacle is that tide::Body's reader is futures::io::AsyncBufRead (to be specific: Box<dyn AsyncBufRead + Unpin + Send + Sync + 'static>), while multipart_async::server::Multipart::with_body(...) accepts futures::stream::Stream, and I can't find a way to convert the AsyncBufRead into the Stream.

I tried implementing some kind of adapter that would store buffered values from AsyncBufRead and implement Stream, but looks like I'm not experienced enough to do that.

jbr commented 3 years ago

I'm not sure if it will work with that multipart library, but you can get a stream from a Read/AsyncRead with https://docs.rs/async-std/1.9.0/async_std/io/prelude/trait.ReadExt.html#method.bytes