Issue: Registry returns 500 'An error occurred' if Content-Length header is provided

registry
priority:low
triaged

(Bence Frenyó) #1

What I Wanted to Do and What Happened

Our electron based application uses npm registry to query module updates which returns status code 500 with the text: ‘An error occurred’. This happens since end of May when npm migrated to new CDN.

It happens because electron.net module sets Content-Length: 0 header.

Reproduction Steps

Based on comment by @mrodem here: https://github.com/npm/registry/issues/330#issuecomment-392492622

$ npm install electron

$ cat > registry-test.js
const {app} = require('electron');
app.on('ready', () => {
    const {net} = require('electron');
    const request = net.request('https://registry.npmjs.org/underscore');
    request.on('response', (response) => {
        console.log(`STATUS: ${response.statusCode}`);
        console.log(`HEADERS: ${JSON.stringify(response.headers)}`);
        response.on('data', (chunk) => {
            console.log(`BODY: ${chunk}`);
        });
        response.on('end', () => {
            console.log('No more data in response.');
        });
    });
    request.end();
});
^D

$ node_modules/.bin/electron registry-test.js

Platform Info

$ npm --versions
{ npm: '6.1.0',
  ares: '1.14.0',
  cldr: '33.1',
  http_parser: '2.8.0',
  icu: '62.1',
  modules: '64',
  napi: '3',
  nghttp2: '1.32.0',
  node: '10.7.0',
  openssl: '1.1.0h',
  tz: '2018e',
  unicode: '11.0',
  uv: '1.22.0',
  v8: '6.7.288.49-node.15',
  zlib: '1.2.11' }
$ node -p process.platform
win32

(Rebecca Turner) #2

This has been fixed (as of about 1 hour ago). GET and HEAD requests with a Content-Length: 0 will no longer produce 500s.


(Bence Frenyó) #3

Great, it’s working, thank you!