warp
warp copied to clipboard
Progressbar callback when serving large files
Hi there, This is some awesome work!
Is your feature request related to a problem? Please describe.
I would like to serve large files via warp
(already works), and display a progress bar as they are downloaded.
Describe the solution you'd like
I would like to be able to somehow add this to the logger via the Info
struct, and specify my own callback for it:
let logging = warp::log::custom(|info| {
println!(
"{} {} - - {} [{:?}] {} {} {}",
info.progress(my_progress_callback),
info.remote_addr().unwrap().ip(),
info.status().as_u16(),
chrono::offset::Local::now(),
info.path(),
info.referer().unwrap_or("NoReferer"),
info.user_agent().unwrap()
);
});
Describe alternatives you've considered Any alternative is welcome.
You realize that the suggested logging would enable progress indication on the server side only, not in the client (which probably already have progress indication for files large enough that the acutal data transfer takes is relevant for the duration)? Where would you display that progress bar?
Oh, true. What would be the better approach here?
Perhaps a URL callback or just a server-side endpoint reporting back the progress in case of a GET
.
(This is just for the sake of completeness: progress on both server and client side. Initial feature request was for the server. :smile:)
Ok, seems mpart-async has a mechanism to tackle a POST
from the client.
Something like:
while let Ok(Some(bytes)) = field.try_next().await {
callback(bytes.len());
}
The callback can then handle the bytes and maintain a state of how many were already received and can call an update of the progressbar.