diff options
author | Anna Henningsen <anna@addaleax.net> | 2018-04-05 22:51:49 +0200 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2018-04-05 23:00:02 +0200 |
commit | e37effe4cec98688e75d770f4d0b7f68927e2b73 (patch) | |
tree | e7efa0fc8a2139f9aba4b66ea3f3613262f20cef /deps/npm/node_modules/npm-profile/node_modules/make-fetch-happen/node_modules/http-proxy-agent/node_modules/agent-base/index.js | |
parent | 026f6b787a7a23597790f1f0b076c58a68c7c38b (diff) | |
download | android-node-v8-e37effe4cec98688e75d770f4d0b7f68927e2b73.tar.gz android-node-v8-e37effe4cec98688e75d770f4d0b7f68927e2b73.tar.bz2 android-node-v8-e37effe4cec98688e75d770f4d0b7f68927e2b73.zip |
Revert "deps: upgrade npm to 5.8.0"
This reverts commit 25a816dcda7b1db0929501acfe13f2fe5119759b.
PR-URL: https://github.com/nodejs/node/pull/19837
Reviewed-By: Gus Caplan <me@gus.host>
Diffstat (limited to 'deps/npm/node_modules/npm-profile/node_modules/make-fetch-happen/node_modules/http-proxy-agent/node_modules/agent-base/index.js')
-rw-r--r-- | deps/npm/node_modules/npm-profile/node_modules/make-fetch-happen/node_modules/http-proxy-agent/node_modules/agent-base/index.js | 58 |
1 files changed, 28 insertions, 30 deletions
diff --git a/deps/npm/node_modules/npm-profile/node_modules/make-fetch-happen/node_modules/http-proxy-agent/node_modules/agent-base/index.js b/deps/npm/node_modules/npm-profile/node_modules/make-fetch-happen/node_modules/http-proxy-agent/node_modules/agent-base/index.js index b1f42e6317..df3ca727a7 100644 --- a/deps/npm/node_modules/npm-profile/node_modules/make-fetch-happen/node_modules/http-proxy-agent/node_modules/agent-base/index.js +++ b/deps/npm/node_modules/npm-profile/node_modules/make-fetch-happen/node_modules/http-proxy-agent/node_modules/agent-base/index.js @@ -1,14 +1,19 @@ 'use strict'; + +/** + * Module dependencies. + */ + require('./patch-core'); const inherits = require('util').inherits; const promisify = require('es6-promisify'); const EventEmitter = require('events').EventEmitter; -module.exports = Agent; +/** + * Module exports. + */ -function isAgent(v) { - return v && typeof v.addRequest === 'function'; -} +module.exports = Agent; /** * Base `http.Agent` implementation. @@ -17,6 +22,7 @@ function isAgent(v) { * @param {Function} callback * @api public */ + function Agent(callback, _opts) { if (!(this instanceof Agent)) { return new Agent(callback, _opts); @@ -24,10 +30,6 @@ function Agent(callback, _opts) { EventEmitter.call(this); - // The callback gets promisified if it has 3 parameters - // (i.e. it has a callback function) lazily - this._promisifiedCallback = false; - let opts = _opts; if ('function' === typeof callback) { this.callback = callback; @@ -57,15 +59,19 @@ Agent.prototype.callback = function callback(req, opts) { * * @api public */ -Agent.prototype.addRequest = function addRequest(req, _opts) { + +Agent.prototype.addRequest = function addRequest( + req, + _opts +) { const ownOpts = Object.assign({}, _opts); - // Set default `host` for HTTP to localhost + // set default `host` for HTTP to localhost if (null == ownOpts.host) { ownOpts.host = 'localhost'; } - // Set default `port` for HTTP if none was explicitly specified + // set default `port` for HTTP if none was explicitly specified if (null == ownOpts.port) { ownOpts.port = ownOpts.secureEndpoint ? 443 : 80; } @@ -73,7 +79,7 @@ Agent.prototype.addRequest = function addRequest(req, _opts) { const opts = Object.assign({}, this.options, ownOpts); if (opts.host && opts.path) { - // If both a `host` and `path` are specified then it's most likely the + // if both a `host` and `path` are specified then it's most likely the // result of a `url.parse()` call... we need to remove the `path` portion so // that `net.connect()` doesn't attempt to open that as a unix socket file. delete opts.path; @@ -85,12 +91,12 @@ Agent.prototype.addRequest = function addRequest(req, _opts) { delete opts.defaultPort; delete opts.createConnection; - // Hint to use "Connection: close" + // hint to use "Connection: close" // XXX: non-documented `http` module API :( req._last = true; req.shouldKeepAlive = false; - // Create the `stream.Duplex` instance + // create the `stream.Duplex` instance let timeout; let timedOut = false; const timeoutMs = this.timeout; @@ -104,7 +110,6 @@ Agent.prototype.addRequest = function addRequest(req, _opts) { } function ontimeout() { - timeout = null; timedOut = true; const err = new Error( 'A "socket" was not created for HTTP request before ' + timeoutMs + 'ms' @@ -117,7 +122,6 @@ Agent.prototype.addRequest = function addRequest(req, _opts) { if (timedOut) return; if (timeout != null) { clearTimeout(timeout); - timeout = null; } onerror(err); } @@ -126,26 +130,18 @@ Agent.prototype.addRequest = function addRequest(req, _opts) { if (timedOut) return; if (timeout != null) { clearTimeout(timeout); - timeout = null; } - if (isAgent(socket)) { - // `socket` is actually an http.Agent instance, so relinquish - // responsibility for this `req` to the Agent from here on - socket.addRequest(req, opts); - } else if (socket) { + if (socket) { req.onSocket(socket); } else { - const err = new Error( - `no Duplex stream was returned to agent-base for \`${req.method} ${req.path}\`` - ); + const err = new Error(`no Duplex stream was returned to agent-base for \`${req.method} ${req.path}\``); onerror(err); } } - if (!this._promisifiedCallback && this.callback.length >= 3) { - // Legacy callback function - convert to a Promise + if (this.callback.length >= 3) { + // legacy callback function, convert to Promise this.callback = promisify(this.callback, this); - this._promisifiedCallback = true; } if (timeoutMs > 0) { @@ -153,8 +149,10 @@ Agent.prototype.addRequest = function addRequest(req, _opts) { } try { - Promise.resolve(this.callback(req, opts)).then(onsocket, callbackError); + Promise.resolve(this.callback(req, opts)) + .then(onsocket, callbackError); } catch (err) { - Promise.reject(err).catch(callbackError); + Promise.reject(err) + .catch(callbackError); } }; |