Comparing version 0.14.0 to 0.15.0
@@ -0,1 +1,5 @@ | ||
0.15.0 / 2022-05-20 | ||
================== | ||
* use keepAlive by default for requests | ||
0.14.0 / 2021-10-29 | ||
@@ -2,0 +6,0 @@ ================== |
@@ -15,2 +15,3 @@ /* | ||
const HttpsProxyAgent = require('https-proxy-agent'); | ||
const url = require('url'); | ||
@@ -28,2 +29,3 @@ const {async_all, ensure_timestamp} = require('./utils'); | ||
path: '', | ||
keepAlive: true, | ||
}; | ||
@@ -36,2 +38,8 @@ | ||
const metrics = { | ||
token, | ||
config: {...DEFAULT_CONFIG}, | ||
}; | ||
const {keepAlive} = metrics.config; | ||
// mixpanel constants | ||
@@ -41,10 +49,11 @@ const MAX_BATCH_SIZE = 50; | ||
const REQUEST_LIBS = {http, https}; | ||
const REQUEST_AGENTS = { | ||
http: new http.Agent({keepAlive}), | ||
https: new https.Agent({keepAlive}), | ||
}; | ||
const proxyPath = process.env.HTTPS_PROXY || process.env.HTTP_PROXY; | ||
const proxyAgent = proxyPath ? new HttpsProxyAgent(proxyPath) : null; | ||
const proxyAgent = proxyPath ? new HttpsProxyAgent(Object.assign(url.parse(proxyPath), { | ||
keepAlive, | ||
})) : null; | ||
const metrics = { | ||
token, | ||
config: {...DEFAULT_CONFIG}, | ||
}; | ||
/** | ||
@@ -110,5 +119,3 @@ * sends an async GET or POST request to mixpanel | ||
if (proxyAgent) { | ||
request_options.agent = proxyAgent; | ||
} | ||
request_options.agent = proxyAgent || REQUEST_AGENTS[metrics.config.protocol]; | ||
@@ -115,0 +122,0 @@ if (metrics.config.test) { |
@@ -10,3 +10,3 @@ { | ||
], | ||
"version": "0.14.0", | ||
"version": "0.15.0", | ||
"homepage": "https://github.com/mixpanel/mixpanel-node", | ||
@@ -13,0 +13,0 @@ "author": "Carl Sverre", |
@@ -23,7 +23,12 @@ Mixpanel-node | ||
// initialize mixpanel client configured to communicate over https | ||
// initialize mixpanel client configured to communicate over http instead of https | ||
var mixpanel = Mixpanel.init('<YOUR_TOKEN>', { | ||
protocol: 'https' | ||
protocol: 'http', | ||
}); | ||
// turn off keepAlive (reestablish connection on each request) | ||
var mixpanel = Mixpanel.init('<YOUR_TOKEN>', { | ||
keepAlive: false, | ||
}); | ||
// track an event with optional properties | ||
@@ -30,0 +35,0 @@ mixpanel.track('my event', { |
@@ -16,3 +16,4 @@ var Mixpanel = require('../lib/mixpanel-node'); | ||
protocol: 'https', | ||
path: '' | ||
path: '', | ||
keepAlive: true, | ||
}, "default config is incorrect"); | ||
@@ -19,0 +20,0 @@ test.done(); |
@@ -143,2 +143,26 @@ let Mixpanel; | ||
"default use keepAlive agent": function(test) { | ||
test.expect(2); | ||
var agent = new https.Agent({ keepAlive: false }); | ||
var httpsStub = { | ||
request: Sinon.stub().returns(this.http_emitter).callsArgWith(1, this.res), | ||
Agent: Sinon.stub().returns(agent), | ||
}; | ||
// force SDK not use `undefined` string to initialize proxy-agent | ||
delete process.env.HTTP_PROXY | ||
delete process.env.HTTPS_PROXY | ||
Mixpanel = proxyquire('../lib/mixpanel-node', { | ||
'https': httpsStub | ||
}); | ||
var proxyMixpanel = Mixpanel.init('token'); | ||
proxyMixpanel.send_request({ endpoint: '', data: {} }); | ||
var getConfig = httpsStub.request.firstCall.args[0]; | ||
var agentOpts = httpsStub.Agent.firstCall.args[0]; | ||
test.ok(agentOpts.keepAlive === true, "HTTP Agent wasn't initialized with keepAlive by default"); | ||
test.ok(getConfig.agent === agent, "send_request didn't call https.request with agent"); | ||
test.done(); | ||
}, | ||
"uses correct hostname": function(test) { | ||
@@ -219,4 +243,5 @@ var host = 'testhost.fakedomain'; | ||
var proxyPath = HttpsProxyAgent.firstCall.args[0]; | ||
test.ok(proxyPath === 'this.aint.real.https', "HttpsProxyAgent was not called with the correct proxy path"); | ||
var agentOpts = HttpsProxyAgent.firstCall.args[0]; | ||
test.ok(agentOpts.pathname === "this.aint.real.https", "HttpsProxyAgent was not called with the correct proxy path"); | ||
test.ok(agentOpts.keepAlive === true, "HttpsProxyAgent was not called with the correct proxy path"); | ||
@@ -239,4 +264,4 @@ var getConfig = https.request.firstCall.args[0]; | ||
var proxyPath = HttpsProxyAgent.firstCall.args[0]; | ||
test.ok(proxyPath === 'this.aint.real.https', "HttpsProxyAgent was not called with the correct proxy path"); | ||
var proxyOpts = HttpsProxyAgent.firstCall.args[0]; | ||
test.ok(proxyOpts.pathname === 'this.aint.real.https', "HttpsProxyAgent was not called with the correct proxy path"); | ||
@@ -243,0 +268,0 @@ var getConfig = https.request.firstCall.args[0]; |
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
147940
3137
263
12