set 'content-length' and 'transfer-encoding:gzip' for 'pm2 serve'
Open
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 43.3k
- Forks
- 2.7k
- PR merge metrics
- No merged PRs in 30d
Description
What's going wrong?
I need to download and show loading progress with javascript on web page, but when I'm serving with pm2 serve, there is no way to get the total size of a file downloaded with XmlHttpRequest.
How could we reproduce this issue?
- serve some files with
pm2 serve - in js file:
let xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.responseType = responseType || 'blob';
xhr.onprogress = function(p) {
let contentLength = xhr.getResponseHeader('x-decompressed-content-length')
let contentLength2 = xhr.getResponseHeader('Content-Length')
console.warn(p.loaded, p.total, p.lengthComputable, contentLength, contentLength2)
};
xhr.send(null);
- after funning the js above, the progress info will be logged, and only
p.loadedis available so there is no way to calculate the percentage of the loading progress. And by looking into the network tab of the devtool, it can be seen the 'transfer-encoding' is 'chunked' and the 'content-length' is not set.
Supporting information
# Run the following commands
$ pm2 report
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the pm2 serve command and its static-file response path, then reproduce the XMLHttpRequest case described in the issue and inspect the response headers. Done means served files expose a usable total size through Content-Length or the intended decompressed-length header instead of only chunked transfer encoding.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, nodejs
- Domain
- backend, cli
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100