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

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 +6 -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',
176
+ // 'content-length', upstream response body is modified by proxy, the content-length is not valid anymore.
177
177
  'content-encoding',
178
178
  'transfer-encoding',
179
179
  ];
@@ -198,7 +198,10 @@ async function writeResponseToDownstreamClient(registryInfo, targetUrl, resToDow
198
198
  }
199
199
  }
200
200
  }
201
- resToDownstreamClient.writeHead(upstreamResponse.status, { "content-type": contentType }).end(JSON.stringify(data));
201
+ const bodyData = JSON.stringify(data);
202
+ // body is modified, reset the content-length
203
+ safeHeaders["content-length"] = bodyData.length;
204
+ resToDownstreamClient.writeHead(upstreamResponse.status, safeHeaders).end(bodyData);
202
205
  }
203
206
  else if (contentType.includes('application/octet-stream')) {
204
207
  // 二进制流处理
@@ -247,7 +250,7 @@ async function writeResponseToDownstreamClient(registryInfo, targetUrl, resToDow
247
250
  }
248
251
  else {
249
252
  logger.warn(`Unsupported response content-type from upstream ${targetUrl}`);
250
- resToDownstreamClient.writeHead(upstreamResponse.status, { "content-type": contentType }).end(upstreamResponse.text());
253
+ resToDownstreamClient.writeHead(upstreamResponse.status, safeHeaders).end(upstreamResponse.text());
251
254
  }
252
255
  }
253
256
  catch (err) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "com.jimuwd.xian.registry-proxy",
3
- "version": "1.0.77",
3
+ "version": "1.0.78",
4
4
  "description": "A lightweight npm registry proxy with fallback support",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",