proxying-agent
Advanced tools
Comparing version 0.1.8 to 2.0.0
@@ -10,3 +10,3 @@ 'use strict'; | ||
function ProxyingAgent(options) { | ||
function ProxyingAgent(options, agent) { | ||
this.openSockets = {}; | ||
@@ -21,3 +21,3 @@ this.options = util._extend({}, options); | ||
if (this.options.authType == 'ntlm') { | ||
if (this.options.authType === 'ntlm') { | ||
if (!this.options.proxy.auth) { | ||
@@ -43,14 +43,6 @@ throw new Error('NTLM authentication credentials must be provided'); | ||
// select the Agent type to use based on the proxy protocol | ||
if (this.options.ssl) { | ||
this.agent = https.Agent; | ||
this.options.agent = new https.Agent(); | ||
} else { | ||
this.agent = http.Agent; | ||
this.options.agent = new http.Agent(); | ||
} | ||
this.agent = agent; | ||
this.agent.call(this, this.options); | ||
} | ||
util.inherits(ProxyingAgent, http.Agent); | ||
/** | ||
@@ -61,3 +53,8 @@ * Overrides the 'addRequest' Agent method for establishing a socket with the proxy | ||
ProxyingAgent.prototype.addRequest = function(req, host, port, localAddress) { | ||
if (this.options.authType == 'ntlm') { | ||
if (typeof host === 'object') { | ||
localAddress = host.path; | ||
port = host.port; | ||
host = host.hostname; | ||
} | ||
if (this.options.authType === 'ntlm') { | ||
this.startNtlm(req, host, port, localAddress); | ||
@@ -90,2 +87,4 @@ } else { | ||
tunnelOptions.path = host+':'+port; | ||
tunnelOptions.hostname = this.options.proxy.hostname; | ||
tunnelOptions.port = this.options.proxy.port; | ||
tunnelOptions.headers = tunnelOptions.headers || {}; | ||
@@ -145,3 +144,3 @@ | ||
var protocol = this.options.ssl ? 'https://' : 'http://'; | ||
req.path = protocol+host+':'+port+req.path | ||
req.path = protocol+host+':'+port+req.path; | ||
if (this.authHeader) { | ||
@@ -276,7 +275,15 @@ req.setHeader(this.authHeader.header, this.authHeader.value); | ||
*/ | ||
ProxyingAgent.prototype.createSocket = function(name, host, port, localAddress, req) { | ||
ProxyingAgent.prototype.createSocket = function() { | ||
var req; | ||
if (arguments.length === 2) { | ||
req = arguments[0]; | ||
} else { | ||
req = arguments[4]; | ||
} | ||
if (this.openSockets[req]) { | ||
return this.openSockets[req]; | ||
} | ||
return this.agent.prototype.createSocket.call(this, name, host, port, localAddress, req); | ||
return this.agent.prototype.createSocket.apply(this, arguments); | ||
}; | ||
@@ -300,4 +307,42 @@ | ||
req.onSocket(this.socket); | ||
}; | ||
/** | ||
* HttpProxyingAgent | ||
* @param options | ||
* @constructor | ||
*/ | ||
function HttpProxyingAgent(options) { | ||
ProxyingAgent.call(this, options, http.Agent); | ||
} | ||
util.inherits(HttpProxyingAgent, http.Agent); | ||
util._extend(HttpProxyingAgent.prototype, ProxyingAgent.prototype); | ||
exports.ProxyingAgent = ProxyingAgent; | ||
/** | ||
* HttpsProxyingAgent | ||
* @param options | ||
* @constructor | ||
*/ | ||
function HttpsProxyingAgent(options) { | ||
options.tunnel = true; | ||
ProxyingAgent.call(this, options, https.Agent); | ||
} | ||
util.inherits(HttpsProxyingAgent, https.Agent); | ||
util._extend(HttpsProxyingAgent.prototype, ProxyingAgent.prototype); | ||
/** | ||
* Create the proxying agent | ||
* @param proxy | ||
* @param target | ||
* @returns {*} | ||
*/ | ||
exports.create = function(proxy, target) { | ||
if (typeof proxy === 'string') { | ||
proxy = {proxy: proxy} | ||
} | ||
if (target.indexOf('https:') === 0) { | ||
return new HttpsProxyingAgent(proxy); | ||
} | ||
return new HttpProxyingAgent(proxy); | ||
}; |
{ | ||
"name": "proxying-agent", | ||
"version": "0.1.8", | ||
"version": "2.0.0", | ||
"description": "Node HTTP/HTTPS Forward Proxy Agent", | ||
@@ -28,4 +28,4 @@ "keywords": [ | ||
"engines": { | ||
"node": ">=0.10.0" | ||
"node": ">=0.8.0" | ||
} | ||
} |
@@ -20,23 +20,21 @@ # Node HTTP/HTTPS Forward Proxy Agent | ||
The following options are supported: | ||
### create(options, target) | ||
* ``proxy`` - Specifies the proxy url. The supported format is ``http[s]://[auth@]host:port`` where ``auth`` | ||
is the authentication information in the form of ``username:password``. The authentication information can also be | ||
in the form of a Base64 encoded ``user:password``, e.g. ``http://dXNlcm5hbWU6cGFzc3dvcmQ=@proxy.example.com:8080`` | ||
* ``tunnel`` - If ``true`` then the proxy will become a tunnel to the server. | ||
This should usually be ``true`` only if the target server protocol is ``https`` | ||
* ``tlsOptions`` - TLS connection options to use when the target server protocol is ``https``. See http://nodejs.org/api/tls.html#tls_tls_connect_options_callback for a list of available options. | ||
* ``authType`` - Proxy authentication type. Possible values are ``basic`` and ``ntlm`` (default is ``basic``). | ||
* ``ntlm`` - (beta) applicable only if ``authType`` is ``ntlm``. Supported fields: | ||
* ``domain`` (required) - the NTLM domain | ||
* ``workstation`` (optional) - the local machine hostname (os.hostname() is not specified) | ||
Returns a new agent configured correctly to proxy to the specified target. | ||
* `options` - (string|object) proxy url string or object with the following options: | ||
* `proxy` - Specifies the proxy url. The supported format is `http[s]://[auth@]host:port` where `auth` | ||
is the authentication information in the form of `username:password`. The authentication information can also be | ||
in the form of a Base64 encoded `user:password`, e.g. `http://dXNlcm5hbWU6cGFzc3dvcmQ=@proxy.example.com:8080` | ||
* `tlsOptions` - TLS connection options to use when the target server protocol is `https`. See http://nodejs.org/api/tls.html#tls_tls_connect_options_callback for a list of available options. | ||
* `authType` - Proxy authentication type. Possible values are `basic` and `ntlm` (default is `basic`). | ||
* `ntlm` - (beta) applicable only if `authType` is `ntlm`. Supported fields: | ||
* `domain` (required) - the NTLM domain | ||
* `workstation` (optional) - the local machine hostname (os.hostname() is not specified) | ||
* `target` - the target url that the agent is to proxy | ||
### HTTP Server | ||
```javascript | ||
var proxying = require('proxying-agent'); | ||
var proxyingOptions = { | ||
proxy: 'http://proxy.example.com:8080' | ||
}; | ||
var proxyingAgent = new proxying.ProxyingAgent(proxyingOptions); | ||
var proxyingAgent = require('proxying-agent').create('http://proxy.example.com:8080', 'http://example.com'); | ||
var req = http.request({ | ||
@@ -52,8 +50,3 @@ host: 'example.com', | ||
```javascript | ||
var proxying = require('proxying-agent'); | ||
var proxyingOptions = { | ||
proxy: 'http://proxy.example.com:8080', | ||
tunnel: true | ||
}; | ||
var proxyingAgent = new proxying.ProxyingAgent(proxyingOptions); | ||
var proxyingAgent = require('proxying-agent').create('http://proxy.example.com:8080', 'https://example.com'); | ||
var req = https.request({ | ||
@@ -69,8 +62,3 @@ host: 'example.com', | ||
```javascript | ||
var proxying = require('proxying-agent'); | ||
var proxyingOptions = { | ||
proxy: 'http://username:password@proxy.example.com:8080', | ||
tunnel: true | ||
}; | ||
var proxyingAgent = new proxying.ProxyingAgent(proxyingOptions); | ||
var proxyingAgent = require('proxying-agent').create('http://username:password@proxy.example.com:8080', 'https://example.com'); | ||
var req = https.request({ | ||
@@ -89,6 +77,4 @@ host: 'example.com', | ||
```javascript | ||
var proxying = require('proxying-agent'); | ||
var proxyingOptions = { | ||
var proxyOptions = { | ||
proxy: 'http://username:password@proxy.example.com:8080', | ||
tunnel: true, | ||
authType: 'ntlm', | ||
@@ -99,3 +85,3 @@ ntlm: { | ||
}; | ||
var proxyingAgent = new proxying.ProxyingAgent(proxyingOptions); | ||
var proxyingAgent = require('proxying-agent').create(proxyOptions, 'https://example.com'); | ||
var req = https.request({ | ||
@@ -120,2 +106,2 @@ host: 'example.com', | ||
Copyright 2013-2014 Capriza. Code released under the [MIT license](LICENSE.md) | ||
Copyright 2016 Capriza. Code released under the [MIT license](LICENSE.md) |
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
33611
9
645
1
102
5