com.jimuwd.xian.registry-proxy 1.0.78 → 1.0.79

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +9 -3
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -173,7 +173,7 @@ async function writeResponseToDownstreamClient(registryInfo, targetUrl, resToDow
173
173
  const safeHeaders = { 'connection': connection, 'content-type': contentType, };
174
174
  // 复制所有可能需要的头信息
175
175
  const headersToCopy = [
176
- // 'content-length', upstream response body is modified by proxy, the content-length is not valid anymore.
176
+ 'content-length', // if you modify the body, you must reset the content-length.
177
177
  'content-encoding',
178
178
  'transfer-encoding',
179
179
  ];
@@ -199,8 +199,14 @@ async function writeResponseToDownstreamClient(registryInfo, targetUrl, resToDow
199
199
  }
200
200
  }
201
201
  const bodyData = JSON.stringify(data);
202
- // body is modified, reset the content-length
203
- safeHeaders["content-length"] = bodyData.length;
202
+ if (!safeHeaders["transfer-encoding"]) {
203
+ // if transfer-encoding header is absent, then reset the content-length header.
204
+ // body is modified, reset the content-length
205
+ safeHeaders["content-length"] = bodyData.length;
206
+ }
207
+ else {
208
+ safeHeaders["content-length"] = undefined;
209
+ }
204
210
  resToDownstreamClient.writeHead(upstreamResponse.status, safeHeaders).end(bodyData);
205
211
  }
206
212
  else if (contentType.includes('application/octet-stream')) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "com.jimuwd.xian.registry-proxy",
3
- "version": "1.0.78",
3
+ "version": "1.0.79",
4
4
  "description": "A lightweight npm registry proxy with fallback support",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",