http-proxy-agent
Advanced tools
Comparing version 2.1.0 to 3.0.0
152
index.js
@@ -1,2 +0,1 @@ | ||
/** | ||
@@ -26,27 +25,32 @@ * Module dependencies. | ||
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); | ||
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); | ||
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; | ||
// 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); | ||
// 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 (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; | ||
} | ||
this.proxy = proxy; | ||
this.proxy = proxy; | ||
} | ||
@@ -61,53 +65,67 @@ inherits(HttpProxyAgent, Agent); | ||
HttpProxyAgent.prototype.callback = function connect (req, opts, fn) { | ||
var proxy = this.proxy; | ||
HttpProxyAgent.prototype.callback = function connect(req, opts, fn) { | ||
var proxy = this.proxy; | ||
// change the `http.ClientRequest` instance's "path" field | ||
// to the absolute path of the URL that will be requested | ||
var parsed = url.parse(req.path); | ||
if (null == parsed.protocol) parsed.protocol = 'http:'; | ||
if (null == parsed.hostname) parsed.hostname = opts.hostname || opts.host; | ||
if (null == parsed.port) parsed.port = opts.port; | ||
if (parsed.port == 80) { | ||
// if port is 80, then we can remove the port so that the | ||
// ":80" portion is not on the produced URL | ||
delete parsed.port; | ||
} | ||
var absolute = url.format(parsed); | ||
req.path = absolute; | ||
// change the `http.ClientRequest` instance's "path" field | ||
// to the absolute path of the URL that will be requested | ||
var parsed = url.parse(req.path); | ||
if (null == parsed.protocol) parsed.protocol = 'http:'; | ||
if (null == parsed.hostname) parsed.hostname = opts.hostname || opts.host; | ||
if (null == parsed.port) parsed.port = opts.port; | ||
if (parsed.port == 80) { | ||
// if port is 80, then we can remove the port so that the | ||
// ":80" portion is not on the produced URL | ||
delete parsed.port; | ||
} | ||
var absolute = url.format(parsed); | ||
req.path = absolute; | ||
// inject the `Proxy-Authorization` header if necessary | ||
if (proxy.auth) { | ||
req.setHeader( | ||
'Proxy-Authorization', | ||
'Basic ' + Buffer.from(proxy.auth).toString('base64') | ||
); | ||
} | ||
// inject the `Proxy-Authorization` header if necessary | ||
if (proxy.auth) { | ||
req.setHeader( | ||
'Proxy-Authorization', | ||
'Basic ' + Buffer.from(proxy.auth).toString('base64') | ||
); | ||
} | ||
// create a socket connection to the proxy server | ||
var socket; | ||
if (this.secureProxy) { | ||
socket = tls.connect(proxy); | ||
} else { | ||
socket = net.connect(proxy); | ||
} | ||
// create a socket connection to the proxy server | ||
var socket; | ||
if (this.secureProxy) { | ||
socket = tls.connect(proxy); | ||
} else { | ||
socket = net.connect(proxy); | ||
} | ||
// at this point, the http ClientRequest's internal `_header` field might have | ||
// already been set. If this is the case then we'll need to re-generate the | ||
// string since we just changed the `req.path` | ||
if (req._header) { | ||
debug('regenerating stored HTTP header string for request'); | ||
req._header = null; | ||
req._implicitHeader(); | ||
if (req.output && req.output.length > 0) { | ||
debug('patching connection write() output buffer with updated header'); | ||
// the _header has already been queued to be written to the socket | ||
var first = req.output[0]; | ||
var endOfHeaders = first.indexOf('\r\n\r\n') + 4; | ||
req.output[0] = req._header + first.substring(endOfHeaders); | ||
debug('output buffer: %o', req.output); | ||
} | ||
} | ||
// at this point, the http ClientRequest's internal `_header` field might have | ||
// already been set. If this is the case then we'll need to re-generate the | ||
// string since we just changed the `req.path` | ||
if (req._header) { | ||
debug('regenerating stored HTTP header string for request'); | ||
req._header = null; | ||
req._implicitHeader(); | ||
if (req.output && req.output.length > 0) { | ||
// Node < 12 | ||
debug( | ||
'patching connection write() output buffer with updated header' | ||
); | ||
// the _header has already been queued to be written to the socket | ||
var first = req.output[0]; | ||
var endOfHeaders = first.indexOf('\r\n\r\n') + 4; | ||
req.output[0] = req._header + first.substring(endOfHeaders); | ||
debug('output buffer: %o', req.output); | ||
} else if (req.outputData && req.outputData.length > 0) { | ||
// Node >= 12 | ||
debug( | ||
'patching connection write() output buffer with updated header' | ||
); | ||
var first = req.outputData[0].data; | ||
// the _header has already been queued to be written to the socket | ||
var endOfHeaders = first.indexOf('\r\n\r\n') + 4; | ||
req.outputData[0].data = | ||
req._header + first.substring(endOfHeaders); | ||
debug('output buffer: %o', req.outputData[0].data); | ||
} | ||
} | ||
fn(null, socket); | ||
fn(null, socket); | ||
}; |
{ | ||
"name": "http-proxy-agent", | ||
"version": "2.1.0", | ||
"version": "3.0.0", | ||
"description": "An HTTP(s) proxy `http.Agent` implementation for HTTP", | ||
"main": "./index.js", | ||
"files": [ | ||
"index.js" | ||
], | ||
"scripts": { | ||
@@ -25,12 +28,12 @@ "test": "mocha --reporter spec" | ||
"dependencies": { | ||
"agent-base": "4", | ||
"debug": "3.1.0" | ||
"agent-base": "5", | ||
"debug": "4" | ||
}, | ||
"devDependencies": { | ||
"mocha": "3", | ||
"proxy": "~0.2.3" | ||
"proxy": "1" | ||
}, | ||
"engines": { | ||
"node": ">= 4.5.0" | ||
"node": ">= 6" | ||
} | ||
} |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 2 instances in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 4 instances in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
0
3
7162
3
112
+ Addedagent-base@5.1.1(transitive)
+ Addeddebug@4.3.4(transitive)
+ Addedms@2.1.2(transitive)
- Removedagent-base@4.3.0(transitive)
- Removeddebug@3.1.0(transitive)
- Removedes6-promise@4.2.8(transitive)
- Removedes6-promisify@5.0.0(transitive)
- Removedms@2.0.0(transitive)
Updatedagent-base@5
Updateddebug@4