warp icon indicating copy to clipboard operation
warp copied to clipboard

Progressbar callback when serving large files

Open mihaigalos opened this issue 2 years ago • 4 comments

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.

mihaigalos avatar Apr 16 '22 06:04 mihaigalos

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?

kaj avatar Apr 20 '22 12:04 kaj

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.

mihaigalos avatar Apr 20 '22 12:04 mihaigalos

(This is just for the sake of completeness: progress on both server and client side. Initial feature request was for the server. :smile:)

mihaigalos avatar Apr 20 '22 12:04 mihaigalos

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.

mihaigalos avatar May 02 '22 19:05 mihaigalos