npm-registry-client
Advanced tools
Comparing version 7.1.2 to 7.2.0
@@ -95,4 +95,13 @@ module.exports = regRequest | ||
function makeRequest (uri, params, cb_) { | ||
var cb = once(cb_) | ||
var socket | ||
var cb = once(function (er, parsed, raw, response) { | ||
if (socket) { | ||
// The socket might be returned to a pool for re-use, so don’t keep | ||
// the 'error' listener from here attached. | ||
socket.removeListener('error', cb) | ||
} | ||
return cb_(er, parsed, raw, response) | ||
}) | ||
var parsed = url.parse(uri) | ||
@@ -150,9 +159,40 @@ var headers = {} | ||
var done = requestDone.call(this, params.method, uri, cb) | ||
var req = request(opts, decodeResponseBody(done)) | ||
var req = request(opts, params.streaming ? undefined : decodeResponseBody(done)) | ||
req.on('error', cb) | ||
// This should not be necessary, as the HTTP implementation in Node | ||
// passes errors occurring on the socket to the request itself. Being overly | ||
// cautious comes at a low cost, though. | ||
req.on('socket', function (s) { | ||
s.on('error', cb) | ||
socket = s | ||
socket.on('error', cb) | ||
}) | ||
if (params.streaming) { | ||
req.on('response', function (response) { | ||
if (response.statusCode >= 400) { | ||
var parts = [] | ||
response.on('data', function (data) { | ||
parts.push(data) | ||
}) | ||
response.on('end', function () { | ||
decodeResponseBody(done)(null, response, Buffer.concat(parts)) | ||
}) | ||
} else { | ||
response.on('end', function () { | ||
// don't ever re-use connections that had server errors. | ||
// those sockets connect to the Bad Place! | ||
if (response.socket && response.statusCode > 500) { | ||
response.socket.destroy() | ||
} | ||
}) | ||
return cb(null, response) | ||
} | ||
}) | ||
} | ||
if (params.body && (params.body instanceof Stream)) { | ||
@@ -159,0 +199,0 @@ params.body.pipe(req) |
@@ -5,3 +5,3 @@ { | ||
"description": "Client for the npm registry", | ||
"version": "7.1.2", | ||
"version": "7.2.0", | ||
"repository": { | ||
@@ -8,0 +8,0 @@ "url": "https://github.com/npm/npm-registry-client.git" |
@@ -262,2 +262,4 @@ # npm-registry-client | ||
* `follow` {Boolean} Follow 302/301 responses. Optional (default: true). | ||
* `streaming` {Boolean} Stream the request body as it comes, handling error | ||
responses in a non-streaming way. | ||
* `auth` {Credentials} Optional. | ||
@@ -264,0 +266,0 @@ * `cb` {Function} |
@@ -13,2 +13,10 @@ var server = require('./server.js') | ||
// See https://github.com/npm/npm-registry-client/pull/142 for background. | ||
// Note: `process.on('warning')` only works with Node >= 6. | ||
process.on('warning', function (warning) { | ||
if (/Possible EventEmitter memory leak detected/.test(warning.message)) { | ||
throw new Error('There should not be any EventEmitter memory leaks') | ||
} | ||
}) | ||
module.exports = { | ||
@@ -15,0 +23,0 @@ port: server.port, |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
353188
5719
321