diff options
Diffstat (limited to 'deps/npm/node_modules/pacote/node_modules/make-fetch-happen/node_modules/https-proxy-agent/index.js')
-rw-r--r-- | deps/npm/node_modules/pacote/node_modules/make-fetch-happen/node_modules/https-proxy-agent/index.js | 56 |
1 files changed, 40 insertions, 16 deletions
diff --git a/deps/npm/node_modules/pacote/node_modules/make-fetch-happen/node_modules/https-proxy-agent/index.js b/deps/npm/node_modules/pacote/node_modules/make-fetch-happen/node_modules/https-proxy-agent/index.js index 33207c1454..699857804e 100644 --- a/deps/npm/node_modules/pacote/node_modules/make-fetch-happen/node_modules/https-proxy-agent/index.js +++ b/deps/npm/node_modules/pacote/node_modules/make-fetch-happen/node_modules/https-proxy-agent/index.js @@ -1,4 +1,3 @@ - /** * Module dependencies. */ @@ -23,10 +22,13 @@ module.exports = HttpsProxyAgent; * @api public */ -function HttpsProxyAgent (opts) { +function HttpsProxyAgent(opts) { if (!(this instanceof HttpsProxyAgent)) return new HttpsProxyAgent(opts); if ('string' == typeof opts) opts = url.parse(opts); - if (!opts) throw new Error('an HTTP(S) proxy server `host` and `port` must be specified!'); + if (!opts) + throw new Error( + 'an HTTP(S) proxy server `host` and `port` must be specified!' + ); debug('creating new HttpsProxyAgent instance: %o', opts); Agent.call(this, opts); @@ -39,6 +41,12 @@ function HttpsProxyAgent (opts) { proxy.host = proxy.hostname || proxy.host; proxy.port = +proxy.port || (this.secureProxy ? 443 : 80); + // ALPN is supported by Node.js >= v5. + // attempt to negotiate http/1.1 for proxy servers that support http/2 + if (this.secureProxy && !('ALPNProtocols' in proxy)) { + proxy.ALPNProtocols = ['http 1.1'] + } + if (proxy.host && proxy.path) { // 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 @@ -57,7 +65,7 @@ inherits(HttpsProxyAgent, Agent); * @api public */ -HttpsProxyAgent.prototype.callback = function connect (req, opts, fn) { +HttpsProxyAgent.prototype.callback = function connect(req, opts, fn) { var proxy = this.proxy; // create a socket connection to the proxy server @@ -75,13 +83,13 @@ HttpsProxyAgent.prototype.callback = function connect (req, opts, fn) { var buffers = []; var buffersLength = 0; - function read () { + function read() { var b = socket.read(); if (b) ondata(b); else socket.once('readable', read); } - function cleanup () { + function cleanup() { socket.removeListener('data', ondata); socket.removeListener('end', onend); socket.removeListener('error', onerror); @@ -89,20 +97,20 @@ HttpsProxyAgent.prototype.callback = function connect (req, opts, fn) { socket.removeListener('readable', read); } - function onclose (err) { + function onclose(err) { debug('onclose had error %o', err); } - function onend () { + function onend() { debug('onend'); } - function onerror (err) { + function onerror(err) { cleanup(); fn(err); } - function ondata (b) { + function ondata(b) { buffers.push(b); buffersLength += b.length; var buffered = Buffer.concat(buffers, buffersLength); @@ -133,9 +141,12 @@ HttpsProxyAgent.prototype.callback = function connect (req, opts, fn) { if (opts.secureEndpoint) { // since the proxy is connecting to an SSL server, we have // to upgrade this socket connection to an SSL connection - debug('upgrading proxy-connected socket to TLS connection: %o', opts.host); + debug( + 'upgrading proxy-connected socket to TLS connection: %o', + opts.host + ); opts.socket = socket; - opts.servername = opts.host; + opts.servername = opts.servername || opts.host; opts.host = null; opts.hostname = null; opts.port = null; @@ -159,7 +170,7 @@ HttpsProxyAgent.prototype.callback = function connect (req, opts, fn) { } } - function onsocket (socket) { + function onsocket(socket) { // replay the "buffers" Buffer onto the `socket`, since at this point // the HTTP module machinery has been hooked up for the user if ('function' == typeof socket.ondata) { @@ -192,13 +203,26 @@ HttpsProxyAgent.prototype.callback = function connect (req, opts, fn) { var headers = Object.assign({}, proxy.headers); if (proxy.auth) { - headers['Proxy-Authorization'] = 'Basic ' + new Buffer(proxy.auth).toString('base64'); + headers['Proxy-Authorization'] = + 'Basic ' + new Buffer(proxy.auth).toString('base64'); + } + + // the Host header should only include the port + // number when it is a non-standard port + var host = opts.host; + if (!isDefaultPort(opts.port, opts.secureEndpoint)) { + host += ':' + opts.port; } - headers['Host'] = hostname; + headers['Host'] = host; + headers['Connection'] = 'close'; - Object.keys(headers).forEach(function (name) { + Object.keys(headers).forEach(function(name) { msg += name + ': ' + headers[name] + '\r\n'; }); socket.write(msg + '\r\n'); }; + +function isDefaultPort(port, secure) { + return Boolean((!secure && port === 80) || (secure && port === 443)); +} |