Unitech / Unitech/pm2

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

Open
#5,779 0 comments 0 reactions 0 assignees View on GitHub

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?

  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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.