sindresorhus / got

🌐 Human-friendly and powerful HTTP request library for Node.js
MIT License
14.27k stars 935 forks source link

Stream report downloadProgress when redirects #2343

Open marfgold1 opened 6 months ago

marfgold1 commented 6 months ago

Describe the bug

In got.stream, downloadProgress fired when redirects happens. Every time redirect happens, the progress report from 0 (with total of content-length, undefined if not any) to 1 instantly (with total of 0). Related issue: https://github.com/electron/fiddle-core/issues/59

Actual behavior

downloadProgress triggered every time redirect happens. This makes the progress percent from 0 to 1 and repeat until response.

Expected behavior

downloadProgress should report when it only receive a proper response, not redirect.

Code to reproduce

const { default: got } = require("got");
const dSteram = got.stream('https://github.com/electron/electron/releases/download/v29.1.5/electron-v29.1.5-win32-x64.zip');
dSteram.on('request', (req) => console.log("\n\nREQUEST ===========================", req.path));
dSteram.on('redirect', (req, resp) => {
    console.log('====== REDIRECT ======');
    console.log('FROM: ', req.url);
    console.log('TO: ', resp.url.href);
});
dSteram.on('response', (response) => {
    console.log('======= RESPONSE =======');
    console.log('URL: ', response.url);
});
dSteram.on('downloadProgress', (progress) => {
    console.log('====== PROGRESS ======');
    console.log(progress);
});

Checklist

jdesboeufs commented 6 months ago

Same here. A simple work-around is to wait for response event and check its status.