@cdxoo/npm-lockdown-proxy 0.0.4 → 0.0.5

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/package.json +1 -1
  2. package/proxy.js +8 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cdxoo/npm-lockdown-proxy",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "description": "Minimal npm registry proxy with package/version whitelisting",
5
5
  "bin": {
6
6
  "npm-lockdown-proxy": "./proxy.js",
package/proxy.js CHANGED
@@ -132,7 +132,6 @@ const server = http.createServer((req, res) => {
132
132
 
133
133
  const url = new URL(req.url, UPSTREAM);
134
134
 
135
- // When we need to filter the manifest, request uncompressed so we can parse it.
136
135
  const needsFilter = isMetadata && pkg !== null && whitelist.get(pkg) !== '*';
137
136
  const headers = { ...req.headers, host: url.hostname };
138
137
  if (needsFilter) headers['accept-encoding'] = 'identity';
@@ -155,9 +154,15 @@ const server = http.createServer((req, res) => {
155
154
  const chunks = [];
156
155
  upstream.on('data', chunk => chunks.push(chunk));
157
156
  upstream.on('end', () => {
158
- const filtered = filterManifest(Buffer.concat(chunks), whitelist.get(pkg));
157
+ const raw = Buffer.concat(chunks);
158
+ if (raw.length === 0) {
159
+ res.writeHead(upstream.statusCode, upstream.headers);
160
+ res.end();
161
+ return;
162
+ }
163
+ const filtered = filterManifest(raw, whitelist.get(pkg));
159
164
  const responseHeaders = { ...upstream.headers, 'content-length': filtered.length };
160
- delete responseHeaders['content-encoding'];
165
+ delete responseHeaders['transfer-encoding'];
161
166
  res.writeHead(upstream.statusCode, responseHeaders);
162
167
  res.end(filtered);
163
168
  });