added feature detection for native KeepAlive support in 0.11
This commit is contained in:
48
src/lib/connectors/_custom_agent.js
Normal file
48
src/lib/connectors/_custom_agent.js
Normal file
@ -0,0 +1,48 @@
|
||||
var ForeverAgent = require('forever-agent');
|
||||
var ForeverSSLAgent = require('forever-agent').SSL;
|
||||
|
||||
var NativeAgent = require('http').Agent;
|
||||
var NativeSSLAgent = require('https').Agent;
|
||||
|
||||
var inherits = require('util').inherits;
|
||||
var nativeKeepAlive = (function () {
|
||||
var a = new NativeAgent();
|
||||
return !!a.freeSockets;
|
||||
}());
|
||||
|
||||
function WrapForeverAgent(opts) {
|
||||
ForeverAgent.call(this, opts);
|
||||
var _addRequest = this.addRequest;
|
||||
this.addRequest = function (req, host, port) {
|
||||
req.useChunkedEncodingByDefault = false;
|
||||
_addRequest.call(this, req, host, port);
|
||||
};
|
||||
}
|
||||
inherits(WrapForeverAgent, ForeverAgent);
|
||||
|
||||
function WrapForeverSSLAgent(opts) {
|
||||
ForeverSSLAgent.call(this, opts);
|
||||
var _addRequest = this.addRequest;
|
||||
this.addRequest = function (req, host, port) {
|
||||
req.useChunkedEncodingByDefault = false;
|
||||
_addRequest.call(this, req, host, port);
|
||||
};
|
||||
}
|
||||
inherits(WrapForeverSSLAgent, ForeverSSLAgent);
|
||||
|
||||
function WrapNativeAgent(opts) { NativeAgent.call(this, opts); }
|
||||
inherits(WrapNativeAgent, NativeAgent);
|
||||
|
||||
function WrapNativeSSLAgent(opts) { NativeSSLAgent.call(this, opts); }
|
||||
inherits(WrapNativeSSLAgent, NativeSSLAgent);
|
||||
|
||||
|
||||
if (nativeKeepAlive) {
|
||||
module.exports = WrapNativeAgent;
|
||||
module.exports.SSL = WrapNativeSSLAgent;
|
||||
} else {
|
||||
module.exports = WrapForeverAgent;
|
||||
module.exports.SSL = WrapForeverSSLAgent;
|
||||
}
|
||||
|
||||
module.exports.supportsNativeKeepAlive = nativeKeepAlive;
|
||||
Reference in New Issue
Block a user