forked from pubnub/javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode.js
More file actions
29 lines (23 loc) · 916 Bytes
/
node.js
File metadata and controls
29 lines (23 loc) · 916 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/* @flow */
import superagent from 'superagent';
import superagentProxy from 'superagent-proxy';
import AgentKeepAlive from 'agentkeepalive';
let keepAliveAgent: (AgentKeepAlive | AgentKeepAlive.HttpsAgent) = null;
let keepAliveSecureAgent: (AgentKeepAlive | AgentKeepAlive.HttpsAgent) = null;
superagentProxy(superagent);
export function proxy(superagentConstruct: superagent) {
return superagentConstruct.proxy(this._config.proxy);
}
export function keepAlive(superagentConstruct: superagent) {
let agent = this._config.secure ? keepAliveSecureAgent : keepAliveAgent;
if (agent === null) {
let AgentClass = this._config.secure ? AgentKeepAlive.HttpsAgent : AgentKeepAlive;
agent = new AgentClass(this._config.keepAliveSettings);
if (this._config.secure) {
keepAliveSecureAgent = agent;
} else {
keepAliveAgent = agent;
}
}
return superagentConstruct.agent(agent);
}