com.jimuwd.xian.registry-proxy 1.0.87 → 1.0.89

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 -9
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -154,7 +154,13 @@ async function fetchFromRegistry(registry, targetUrl, reqFromDownstreamClient, l
154
154
  mergedHeaders.host = upstreamHost;
155
155
  }
156
156
  const response = await fetch(targetUrl, { headers: mergedHeaders });
157
- logger.info(`Response from upstream ${targetUrl}: ${response.status} ${response.statusText} content-type=${response.headers.get('content-type')} content-length=${response.headers.get('content-length')} transfer-encoding=${response.headers.get('transfer-encoding')}`);
157
+ logger.info(`
158
+ Response from upstream ${targetUrl}: ${response.status} ${response.statusText}
159
+ content-type=${response.headers.get('content-type')}
160
+ content-encoding=${response.headers.get('content-encoding')}
161
+ content-length=${response.headers.get('content-length')}
162
+ transfer-encoding=${response.headers.get('transfer-encoding')}
163
+ `);
158
164
  return response.ok ? response : null;
159
165
  }
160
166
  catch (e) {
@@ -172,12 +178,6 @@ async function fetchFromRegistry(registry, targetUrl, reqFromDownstreamClient, l
172
178
  limiter.release();
173
179
  }
174
180
  }
175
- function resetHeaderContentLengthIfTransferEncodingIsAbsent(safeHeaders, targetUrl, bodyData) {
176
- if (!safeHeaders["transfer-encoding"]) {
177
- logger.info(`Transfer-Encoding header is absent, then set the content-length header, upstream url is ${targetUrl}`);
178
- safeHeaders["content-length"] = Buffer.byteLength(bodyData);
179
- }
180
- }
181
181
  async function writeResponseToDownstreamClient(registryInfo, targetUrl, resToDownstreamClient, upstreamResponse, reqFromDownstreamClient, proxyInfo, proxyPort, registryInfos) {
182
182
  if (!upstreamResponse.ok)
183
183
  throw new Error("Only 2xx upstream response is supported");
@@ -199,7 +199,7 @@ async function writeResponseToDownstreamClient(registryInfo, targetUrl, resToDow
199
199
  }
200
200
  }
201
201
  const bodyData = JSON.stringify(data);
202
- const safeHeaders = { 'content-type': 'application/json', 'content-length': Buffer.byteLength(bodyData) };
202
+ const safeHeaders = { 'content-type': contentType, 'content-length': Buffer.byteLength(bodyData) };
203
203
  logger.info(`Response to downstream client headers`, JSON.stringify(safeHeaders), targetUrl);
204
204
  resToDownstreamClient.writeHead(upstreamResponse.status, { 'content-type': 'application/json' }).end(bodyData);
205
205
  }
@@ -216,7 +216,6 @@ async function writeResponseToDownstreamClient(registryInfo, targetUrl, resToDow
216
216
  });
217
217
  if (!safeHeaders['content-type'])
218
218
  safeHeaders['content-type'] = 'application/octet-stream';
219
- const contentType = safeHeaders['content-type'];
220
219
  if (!upstreamResponse.body) {
221
220
  logger.error(`Empty response body from upstream ${targetUrl}`);
222
221
  resToDownstreamClient.writeHead(502).end('Empty Upstream Response');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "com.jimuwd.xian.registry-proxy",
3
- "version": "1.0.87",
3
+ "version": "1.0.89",
4
4
  "description": "A lightweight npm registry proxy with fallback support",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",