Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function HttpProxyAgent(opts) {
if (!(this instanceof HttpProxyAgent)) return new HttpProxyAgent(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!'
);
debug('creating new HttpProxyAgent instance: %o', opts);
Agent.call(this, opts);
var proxy = Object.assign({}, opts);
// if `true`, then connect to the proxy server over TLS. defaults to `false`.
this.secureProxy = proxy.protocol
? /^https:?$/i.test(proxy.protocol)
: false;
// prefer `hostname` over `host`, and set the `port` if needed
proxy.host = proxy.hostname || proxy.host;
proxy.port = +proxy.port || (this.secureProxy ? 443 : 80);
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
// that `net.connect()` doesn't attempt to open that as a unix socket file.
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!'
);
debug('creating new HttpsProxyAgent instance: %o', opts);
Agent.call(this, opts);
var proxy = Object.assign({}, opts);
// if `true`, then connect to the proxy server over TLS. defaults to `false`.
this.secureProxy = proxy.protocol
? /^https:?$/i.test(proxy.protocol)
: false;
// prefer `hostname` over `host`, and set the `port` if needed
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'];
function HttpProxyAgent(opts) {
if (!(this instanceof HttpProxyAgent)) return new HttpProxyAgent(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!');
debug('creating new HttpProxyAgent instance: %o', opts);
Agent.call(this, opts);
var proxy = Object.assign({}, opts);
// if `true`, then connect to the proxy server over TLS. defaults to `false`.
this.secureProxy = proxy.protocol ? /^https:?$/i.test(proxy.protocol) : false;
// prefer `hostname` over `host`, and set the `port` if needed
proxy.host = proxy.hostname || proxy.host;
proxy.port = +proxy.port || (this.secureProxy ? 443 : 80);
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
// that `net.connect()` doesn't attempt to open that as a unix socket file.
delete proxy.path;
delete proxy.pathname;
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!');
}
debug('creating new HttpsProxyAgent instance: %o', opts);
Agent.call(this, connect);
var proxy = extend({}, opts);
// if `true`, then connect to the proxy server over TLS. defaults to `false`.
this.secureProxy = proxy.protocol ? /^https:?$/i.test(proxy.protocol) : false;
// prefer `hostname` over `host`, and set the `port` if needed
proxy.host = proxy.hostname || proxy.host;
proxy.port = proxy.port || (this.secureProxy ? 443 : 80);
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
// that `net.connect()` doesn't attempt to open that as a unix socket file.
delete proxy.path;
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!'
);
debug('creating new HttpsProxyAgent instance: %o', opts);
Agent.call(this, opts);
var proxy = Object.assign({}, opts);
// if `true`, then connect to the proxy server over TLS. defaults to `false`.
this.secureProxy = proxy.protocol
? /^https:?$/i.test(proxy.protocol)
: false;
// prefer `hostname` over `host`, and set the `port` if needed
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'];
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!'
);
debug('creating new HttpsProxyAgent instance: %o', opts);
Agent.call(this, opts);
var proxy = Object.assign({}, opts);
// if `true`, then connect to the proxy server over TLS. defaults to `false`.
this.secureProxy = proxy.protocol ? /^https:?$/i.test(proxy.protocol) : false;
// prefer `hostname` over `host`, and set the `port` if needed
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']
}
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!');
debug('creating new HttpsProxyAgent instance: %o', opts);
Agent.call(this, connect);
var proxy = extend({}, opts);
// if `true`, then connect to the proxy server over TLS. defaults to `false`.
this.secureProxy = proxy.protocol ? /^https:?$/i.test(proxy.protocol) : false;
// prefer `hostname` over `host`, and set the `port` if needed
proxy.host = proxy.hostname || proxy.host;
proxy.port = +proxy.port || (this.secureProxy ? 443 : 80);
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
// that `net.connect()` doesn't attempt to open that as a unix socket file.
delete proxy.path;
delete proxy.pathname;
if (opts.href) {
if (opts.path && !opts.pathname) {
opts.pathname = opts.path;
}
opts.slashes = true;
uri = format(opts);
} else {
uri = opts.uri;
}
}
if (!opts) opts = {};
if (!uri) throw new Error('a PAC file URI must be specified!');
debug('creating PacProxyAgent with URI %o and options %o', uri, opts);
Agent.call(this, connect);
// strip the "pac+" prefix
this.uri = uri.replace(/^pac\+/i, '');
this.sandbox = opts.sandbox;
this.proxy = opts;
this.cache = this._resolver = null;
}
inherits(PacProxyAgent, Agent);
function SocksProxyAgent(opts) {
if (!(this instanceof SocksProxyAgent)) return new SocksProxyAgent(opts);
if ('string' == typeof opts) opts = url.parse(opts);
if (!opts)
throw new Error(
'a SOCKS proxy server `host` and `port` must be specified!'
);
Agent.call(this, opts);
var proxy = Object.assign({}, opts);
// prefer `hostname` over `host`, because of `url.parse()`
proxy.host = proxy.hostname || proxy.host;
// SOCKS doesn't *technically* have a default port, but this is
// the same default that `curl(1)` uses
proxy.port = +proxy.port || 1080;
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
// that `net.connect()` doesn't attempt to open that as a unix socket file.
delete proxy.path;
delete proxy.pathname;
if (opts.href) {
if (opts.path && !opts.pathname) {
opts.pathname = opts.path;
}
opts.slashes = true;
uri = format(opts);
} else {
uri = opts.uri;
}
}
if (!opts) opts = {};
if (!uri) throw new Error('a PAC file URI must be specified!');
debug('creating PacProxyAgent with URI %o and options %o', uri, opts);
Agent.call(this, connect);
// strip the "pac+" prefix
this.uri = uri.replace(/^pac\+/i, '');
this.sandbox = opts.sandbox;
this.proxy = opts;
this.cache = this._resolver = null;
}