Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set 'content-length' and 'transfer-encoding:gzip' for 'pm2 serve' #5779

Open
skywalkershen opened this issue Mar 5, 2024 · 0 comments
Open

Comments

@skywalkershen
Copy link

skywalkershen commented Mar 5, 2024

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?

  1. serve some files with pm2 serve
  2. 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);
  1. after funning the js above, the progress info will be logged, and only p.loaded is 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant