This repository has been archived by the owner on Dec 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: use keep alive agents for all fragment requests
- Loading branch information
1 parent
52812a3
commit fa433e7
Showing
6 changed files
with
85 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
'use strict'; | ||
const Agent = require('agentkeepalive'); | ||
const { SOCKET_TTL } = require('./constants'); | ||
|
||
class AgentStore { | ||
constructor() { | ||
const defaultAgentOpts = { socketActiveTTL: SOCKET_TTL }; | ||
this.httpAgent = new Agent(defaultAgentOpts); | ||
this.httpsAgent = new Agent.HttpsAgent(defaultAgentOpts); | ||
} | ||
|
||
getAgent(protocol) { | ||
if (protocol === 'http:') { | ||
return this.httpAgent; | ||
} | ||
return this.httpsAgent; | ||
} | ||
} | ||
|
||
module.exports = new AgentStore(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
'use strict'; | ||
|
||
/** | ||
* Sets the timeout for the socket active time to live even if its in use. | ||
*/ | ||
const SOCKET_TTL = 60 * 1000; | ||
|
||
module.exports = { | ||
SOCKET_TTL | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
'use strict'; | ||
const { parse } = require('url'); | ||
const Agent = require('agentkeepalive'); | ||
const assert = require('assert'); | ||
const agentStore = require('../lib/agent-store'); | ||
|
||
describe('Agent Store', () => { | ||
it('should get https agent by default', () => { | ||
const agent = agentStore.getAgent(); | ||
assert(agent instanceof Agent.HttpsAgent); | ||
}); | ||
|
||
it('shoulg get http agent for http endpoints', () => { | ||
const { protocol } = parse('http://test.com'); | ||
const agent = agentStore.getAgent(protocol); | ||
assert(agent instanceof Agent); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,15 @@ agentkeepalive@^2.0.3: | |
version "2.2.0" | ||
resolved "https://registry.yarnpkg.com/agentkeepalive/-/agentkeepalive-2.2.0.tgz#c5d1bd4b129008f1163f236f86e5faea2026e2ef" | ||
|
||
agentkeepalive@^4.0.0: | ||
version "4.0.0" | ||
resolved "https://registry.yarnpkg.com/agentkeepalive/-/agentkeepalive-4.0.0.tgz#777e7e4c828bde2690cc7a374ede587d45ba4271" | ||
integrity sha512-McCjHBAI3FGTy9XOMDr/8qzXK4VBL3h+O/TqlBdsyiwX21SdPCQhPIX0Y1HS5ctO5m2maVQRJWEn0IrzKRB6oQ== | ||
dependencies: | ||
debug "^4.1.0" | ||
depd "^1.1.2" | ||
humanize-ms "^1.2.1" | ||
|
||
ajv-keywords@^1.0.0: | ||
version "1.5.1" | ||
resolved "https://registry.yarnpkg.com/ajv-keywords/-/ajv-keywords-1.5.1.tgz#314dd0a4b3368fad3dfcdc54ede6171b886daf3c" | ||
|
@@ -423,6 +432,13 @@ debug@^3.1.0: | |
dependencies: | ||
ms "2.0.0" | ||
|
||
debug@^4.1.0: | ||
version "4.1.1" | ||
resolved "https://registry.yarnpkg.com/debug/-/debug-4.1.1.tgz#3b72260255109c6b589cee050f1d516139664791" | ||
integrity sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw== | ||
dependencies: | ||
ms "^2.1.1" | ||
|
||
decamelize@^1.0.0: | ||
version "1.2.0" | ||
resolved "https://registry.yarnpkg.com/decamelize/-/decamelize-1.2.0.tgz#f6534d15148269b20352e7bee26f501f9a191290" | ||
|
@@ -464,6 +480,11 @@ delayed-stream@~1.0.0: | |
version "1.0.0" | ||
resolved "https://registry.yarnpkg.com/delayed-stream/-/delayed-stream-1.0.0.tgz#df3ae199acadfb7d440aaae0b29e2272b24ec619" | ||
|
||
depd@^1.1.2: | ||
version "1.1.2" | ||
resolved "https://registry.yarnpkg.com/depd/-/depd-1.1.2.tgz#9bcd52e14c097763e749b274c4346ed2e560b5a9" | ||
integrity sha1-m81S4UwJd2PnSbJ0xDRu0uVgtak= | ||
|
||
[email protected]: | ||
version "3.2.0" | ||
resolved "https://registry.yarnpkg.com/diff/-/diff-3.2.0.tgz#c9ce393a4b7cbd0b058a725c93df299027868ff9" | ||
|
@@ -893,6 +914,13 @@ https-proxy-agent@^2.1.0: | |
agent-base "^4.1.0" | ||
debug "^3.1.0" | ||
|
||
humanize-ms@^1.2.1: | ||
version "1.2.1" | ||
resolved "https://registry.yarnpkg.com/humanize-ms/-/humanize-ms-1.2.1.tgz#c46e3159a293f6b896da29316d8b6fe8bb79bbed" | ||
integrity sha1-xG4xWaKT9riW2ikxbYtv6Lt5u+0= | ||
dependencies: | ||
ms "^2.0.0" | ||
|
||
iamdee@^0.4.0: | ||
version "0.4.0" | ||
resolved "https://registry.yarnpkg.com/iamdee/-/iamdee-0.4.0.tgz#4c4872db5e82229a361eabad543c160d7f16959d" | ||
|
@@ -1299,6 +1327,11 @@ [email protected]: | |
version "2.0.0" | ||
resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8" | ||
|
||
ms@^2.0.0, ms@^2.1.1: | ||
version "2.1.1" | ||
resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.1.tgz#30a5864eb3ebb0a66f2ebe6d727af06a09d86e0a" | ||
integrity sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg== | ||
|
||
[email protected]: | ||
version "0.0.7" | ||
resolved "https://registry.yarnpkg.com/mute-stream/-/mute-stream-0.0.7.tgz#3075ce93bc21b8fab43e1bc4da7e8115ed1e7bab" | ||
|