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

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 +8 -11
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -172,11 +172,7 @@ async function writeResponseToDownstreamClient(registryInfo, targetUrl, resToDow
172
172
  // 准备通用头信息
173
173
  const safeHeaders = { 'connection': connection, 'content-type': contentType, };
174
174
  // 复制所有可能需要的头信息
175
- const headersToCopy = [
176
- 'content-length', // if you modify the body, you must reset the content-length.
177
- 'content-encoding',
178
- 'transfer-encoding',
179
- ];
175
+ const headersToCopy = ['content-encoding', 'transfer-encoding',];
180
176
  headersToCopy.forEach(header => {
181
177
  const value = upstreamResponse.headers.get(header);
182
178
  if (value)
@@ -200,13 +196,9 @@ async function writeResponseToDownstreamClient(registryInfo, targetUrl, resToDow
200
196
  }
201
197
  const bodyData = JSON.stringify(data);
202
198
  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
199
+ // if transfer-encoding header is absent, then set the content-length header.
205
200
  safeHeaders["content-length"] = bodyData.length;
206
201
  }
207
- else {
208
- safeHeaders["content-length"] = undefined;
209
- }
210
202
  resToDownstreamClient.writeHead(upstreamResponse.status, safeHeaders).end(bodyData);
211
203
  }
212
204
  else if (contentType.includes('application/octet-stream')) {
@@ -256,7 +248,12 @@ async function writeResponseToDownstreamClient(registryInfo, targetUrl, resToDow
256
248
  }
257
249
  else {
258
250
  logger.warn(`Unsupported response content-type from upstream ${targetUrl}`);
259
- resToDownstreamClient.writeHead(upstreamResponse.status, safeHeaders).end(upstreamResponse.text());
251
+ const bodyData = await upstreamResponse.text();
252
+ if (!safeHeaders["transfer-encoding"]) {
253
+ // if transfer-encoding header is absent, then set the content-length header.
254
+ safeHeaders["content-length"] = bodyData.length;
255
+ }
256
+ resToDownstreamClient.writeHead(upstreamResponse.status, safeHeaders).end(bodyData);
260
257
  }
261
258
  }
262
259
  catch (err) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "com.jimuwd.xian.registry-proxy",
3
- "version": "1.0.79",
3
+ "version": "1.0.81",
4
4
  "description": "A lightweight npm registry proxy with fallback support",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",