httpie / cli

🥧 HTTPie CLI — modern, user-friendly command-line HTTP client for the API era. JSON support, colors, sessions, downloads, plugins & more.
https://httpie.io
BSD 3-Clause "New" or "Revised" License
32.71k stars 3.67k forks source link

Average speed is reported incorrectly for resumed downloads #1516

Open sankalp-khare opened 1 year ago

sankalp-khare commented 1 year ago

Checklist


Minimal reproduction code and steps

  1. Download a file using http -dc <address> -o ./somefile
  2. Interrupt the download at a high percentage done (e.g. 95%)
  3. Resume the download with the same command in Step 1
  4. When it completes, observe the average speed printed

The code to compute average speed this divides total file size by the time spent in the current (resumed) invocation of httpie. so the output is a much higher average speed than actual.

We should keep track of how much of the file was downloaded in the current invocation and use that as the numerator over here: https://github.com/httpie/httpie/blob/30a6f73ec806393d897247b4c7268832de811ff7/httpie/output/ui/rich_progress.py#L41

Current result

When I download the last 10% of a file at 5MB/s, the printed average speed is 50MB/s (1/10 the file size => 10x the speed)

Expected result

When I download the last 10% of a file at 5MB/s, the printed average speed should be 5MB/s


Debug output

Please re-run the command with --debug, then copy the entire command & output and paste both below:

$ http --debug <COMPLETE ARGUMENT LIST THAT TRIGGERS THE ERROR>
<COMPLETE OUTPUT>

Additional information, screenshots, or code examples

mikurei commented 11 months ago

Hi, first-time contributor here, wanted to try myself at this issue :) I will propose a PR.