Skip to content

Commit

Permalink
adding keep-alive to http(s) calls
Browse files Browse the repository at this point in the history
  • Loading branch information
frytg committed Aug 5, 2020
1 parent 4308971 commit 84530fd
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 14 deletions.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@swrlab/node-storage-wrapper",
"version": "0.0.7",
"version": "0.0.8",
"description": "Wrapping AWS S3, GCP GCS, file storage",
"main": "./src/index.js",
"engines": {
Expand All @@ -17,13 +17,13 @@
},
"dependencies": {
"@google-cloud/storage": "5.1.2",
"aws-sdk": "2.719.0",
"aws-sdk": "2.726.0",
"node-fetch": "2.6.0",
"uuid": "8.2.0"
"uuid": "8.3.0"
},
"devDependencies": {
"@swrlab/swr-prettier-config": "0.0.2",
"eslint": "^7.5.0",
"eslint": "^7.6.0",
"eslint-plugin-swr": "0.0.3"
},
"prettier": "@swrlab/swr-prettier-config"
Expand Down
27 changes: 26 additions & 1 deletion src/load.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@

// load node utils
const fetch = require('node-fetch');
const http = require('http');
const https = require('https');

// enable keepalive
const httpAgent = new http.Agent({
keepAlive: true,
});
const httpsAgent = new https.Agent({
keepAlive: true,
});

const loadLocalFile = (that, uri) =>
new Promise((resolve, reject) => {
Expand Down Expand Up @@ -59,7 +69,22 @@ module.exports = async function (uri) {
this.sdk.log(this, 'log', ['storage.load.https >', uri]);

// public http(s) endpoint
let file = await fetch(uri);
let file = await fetch(uri, {
method: 'get',

headers: {
'User-Agent': 'node-storage-wrapper',
Connection: 'keep-alive',
},

agent: function (_parsedURL) {
if (_parsedURL.protocol == 'http:') {
return httpAgent;
} else {
return httpsAgent;
}
},
});

if (file.ok) {
file = await file.buffer();
Expand Down
23 changes: 14 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -305,10 +305,10 @@ astral-regex@^1.0.0:
resolved "https://registry.yarnpkg.com/astral-regex/-/astral-regex-1.0.0.tgz#6c8c3fb827dd43ee3918f27b82782ab7658a6fd9"
integrity sha512-+Ryf6g3BKoRc7jfp7ad8tM4TtMiaWvbF/1/sQcZPkkS7ag3D5nMBCe2UfOTONtAkaG0tO0ij3C5Lwmf1EiyjHg==

aws-sdk@2.719.0:
version "2.719.0"
resolved "https://registry.yarnpkg.com/aws-sdk/-/aws-sdk-2.719.0.tgz#346421f3335a7ded2cc6184fbcdbf71e42544d08"
integrity sha512-vqVAeZ2C8VLvL1hJIBCRFnKMomIoWSIUeYjULRiwRlBYH95EgcDY559Mq2rkx+E0733jdf3wNHA+eRVmwHyXvQ==
aws-sdk@2.726.0:
version "2.726.0"
resolved "https://registry.yarnpkg.com/aws-sdk/-/aws-sdk-2.726.0.tgz#075aae1922e67e21285abae1bb081252cff4fec3"
integrity sha512-QRQ7MaW5dprdr/T3vCTC+J8TeUfpM45yWsBuATPcCV/oO8afFHVySwygvGLY4oJuo5Mf4mJn3+JYTquo6CqiaA==
dependencies:
buffer "4.9.2"
events "1.1.1"
Expand Down Expand Up @@ -785,10 +785,10 @@ eslint-visitor-keys@^1.0.0, eslint-visitor-keys@^1.1.0, eslint-visitor-keys@^1.3
resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-1.3.0.tgz#30ebd1ef7c2fdff01c3a4f151044af25fab0523e"
integrity sha512-6J72N8UNa462wa/KFODt/PJ3IU60SDpC3QXC1Hjc1BXXpfL2C9R5+AU7jhe0F6GREqVMh4Juu+NY7xn+6dipUQ==

eslint@^7.5.0:
version "7.5.0"
resolved "https://registry.yarnpkg.com/eslint/-/eslint-7.5.0.tgz#9ecbfad62216d223b82ac9ffea7ef3444671d135"
integrity sha512-vlUP10xse9sWt9SGRtcr1LAC67BENcQMFeV+w5EvLEoFe3xJ8cF1Skd0msziRx/VMC+72B4DxreCE+OR12OA6Q==
eslint@^7.6.0:
version "7.6.0"
resolved "https://registry.yarnpkg.com/eslint/-/eslint-7.6.0.tgz#522d67cfaea09724d96949c70e7a0550614d64d6"
integrity sha512-QlAManNtqr7sozWm5TF4wIH9gmUm2hE3vNRUvyoYAa4y1l5/jxD/PQStEjBMQtCqZmSep8UxrcecI60hOpe61w==
dependencies:
"@babel/code-frame" "^7.0.0"
ajv "^6.10.0"
Expand Down Expand Up @@ -2140,7 +2140,12 @@ [email protected]:
resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.3.2.tgz#1b4af4955eb3077c501c23872fc6513811587131"
integrity sha512-yXJmeNaw3DnnKAOKJE51sL/ZaYfWJRl1pK9dr19YFCu0ObS231AB1/LbqTKRAQ5kw8A90rA6fr4riOUpTZvQZA==

[email protected], uuid@^8.0.0:
[email protected]:
version "8.3.0"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.3.0.tgz#ab738085ca22dc9a8c92725e459b1d507df5d6ea"
integrity sha512-fX6Z5o4m6XsXBdli9g7DtWgAx+osMsRRZFKma1mIUsLCz6vRvv+pz5VNbyu9UEDzpMWulZfvpgb/cmDXVulYFQ==

uuid@^8.0.0:
version "8.2.0"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.2.0.tgz#cb10dd6b118e2dada7d0cd9730ba7417c93d920e"
integrity sha512-CYpGiFTUrmI6OBMkAdjSDM0k5h8SkkiTP4WAjQgDgNB1S3Ou9VBEvr6q0Kv2H1mMk7IWfxYGpMH5sd5AvcIV2Q==
Expand Down

0 comments on commit 84530fd

Please sign in to comment.