Compare commits

...

14 Commits

Author SHA1 Message Date
7b49bba0d2 2.0.10 2022-08-06 22:29:12 +02:00
6600a23a00 fix(core): update 2022-08-06 22:29:12 +02:00
e2845c9992 2.0.9 2022-08-01 17:15:53 +02:00
5e6f2c6fbf fix(core): update 2022-08-01 17:15:52 +02:00
d3d0649b73 2.0.8 2022-08-01 17:10:22 +02:00
fba43df3c4 fix(core): update 2022-08-01 17:10:22 +02:00
c6fa540543 2.0.7 2022-08-01 17:10:11 +02:00
1891b54389 fix(core): update 2022-08-01 17:10:11 +02:00
fee8443af1 2.0.6 2022-07-30 18:43:11 +02:00
c48f956ae3 fix(core): update 2022-07-30 18:43:10 +02:00
4a4b64a2c4 2.0.5 2022-07-30 02:01:20 +02:00
43d4b47782 fix(core): update 2022-07-30 02:01:20 +02:00
6d970cb925 2.0.4 2022-07-30 01:52:04 +02:00
43710c930e fix(core): update 2022-07-30 01:52:04 +02:00
5 changed files with 635 additions and 1866 deletions

2435
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{
"name": "@pushrocks/smartrequest",
"version": "2.0.3",
"version": "2.0.10",
"private": false,
"description": "dropin replacement for request",
"main": "dist_ts/index.js",
@ -26,15 +26,16 @@
"homepage": "https://gitlab.com/pushrocks/smartrequest#README",
"dependencies": {
"@pushrocks/smartpromise": "^3.1.7",
"@pushrocks/smarturl": "^3.0.2",
"@pushrocks/smarturl": "^3.0.3",
"agentkeepalive": "^4.2.1",
"form-data": "^4.0.0"
},
"devDependencies": {
"@gitzone/tsbuild": "^2.1.63",
"@gitzone/tsbuild": "^2.1.65",
"@gitzone/tsrun": "^1.2.37",
"@gitzone/tstest": "^1.0.72",
"@gitzone/tstest": "^1.0.73",
"@pushrocks/tapbundle": "^5.0.4",
"@types/node": "^18.6.2"
"@types/node": "^18.6.4"
},
"files": [
"ts/**/*",

View File

@ -3,6 +3,6 @@
*/
export const commitinfo = {
name: '@pushrocks/smartrequest',
version: '2.0.3',
version: '2.0.10',
description: 'dropin replacement for request'
}

View File

@ -13,6 +13,7 @@ import * as smarturl from '@pushrocks/smarturl';
export { smartpromise, smarturl };
// third party scope
import agentkeepalive from 'agentkeepalive';
import formData from 'form-data';
export { formData };
export { agentkeepalive, formData };

View File

@ -57,38 +57,39 @@ const parseSocketPathAndRoute = (stringToParseArg: string) => {
/**
* a custom http agent to make sure we can set custom keepAlive options for speedy subsequent calls
*/
const httpAgent = new plugins.http.Agent({
const httpAgent = new plugins.agentkeepalive({
keepAlive: true,
maxFreeSockets: 1,
maxFreeSockets: 10,
maxSockets: 100,
maxTotalSockets: 1000,
timeout: 60000,
});
/**
* a custom http agent to make sure we can set custom keepAlive options for speedy subsequent calls
*/
const httpAgentKeepAliveFalse = new plugins.https.Agent({
maxFreeSockets: 0,
keepAlive: false
const httpAgentKeepAliveFalse = new plugins.agentkeepalive({
keepAlive: false,
timeout: 60000
});
/**
* a custom https agent to make sure we can set custom keepAlive options for speedy subsequent calls
*/
const httpsAgent = new plugins.https.Agent({
const httpsAgent = new plugins.agentkeepalive.HttpsAgent({
keepAlive: true,
maxFreeSockets: 1,
maxFreeSockets: 10,
maxSockets: 100,
maxTotalSockets: 1000,
timeout: 60000
});
/**
* a custom https agent to make sure we can set custom keepAlive options for speedy subsequent calls
*/
const httpsAgentKeepAliveFalse = new plugins.https.Agent({
maxFreeSockets: 0,
const httpsAgentKeepAliveFalse = new plugins.agentkeepalive.HttpsAgent({
keepAlive: false,
keepAliveMsecs: 0,
timeout: 60000
});
export let request = async (
@ -97,7 +98,7 @@ export let request = async (
responseStreamArg: boolean = false,
requestDataFunc: (req: plugins.http.ClientRequest) => void = null
): Promise<IExtendedIncomingMessage> => {
const done = plugins.smartpromise.defer<any>();
const done = plugins.smartpromise.defer<IExtendedIncomingMessage>();
// merge options
const defaultOptions: interfaces.ISmartRequestOptions = {
@ -134,16 +135,16 @@ export let request = async (
// lets determine the request module to use
const requestModule = (() => {
switch (true) {
case parsedUrl.protocol === 'https' && optionsArg.keepAlive:
case parsedUrl.protocol === 'https:' && optionsArg.keepAlive:
optionsArg.agent = httpsAgent;
return plugins.https;
case parsedUrl.protocol === 'https' && !optionsArg.keepAlive:
case parsedUrl.protocol === 'https:' && !optionsArg.keepAlive:
optionsArg.agent = httpsAgentKeepAliveFalse;
return plugins.https;
case parsedUrl.protocol === 'http' && optionsArg.keepAlive:
case parsedUrl.protocol === 'http:' && optionsArg.keepAlive:
optionsArg.agent = httpAgent;
return plugins.http;
case parsedUrl.protocol === 'http' && !optionsArg.keepAlive:
case parsedUrl.protocol === 'http:' && !optionsArg.keepAlive:
optionsArg.agent = httpAgentKeepAliveFalse;
return plugins.http;
}
@ -157,7 +158,7 @@ export let request = async (
// lets perform the actual request
const requestToFire = requestModule.request(optionsArg, async (response) => {
if (responseStreamArg) {
done.resolve(response);
done.resolve(response as IExtendedIncomingMessage);
} else {
const builtResponse = await buildUtf8Response(response, optionsArg.autoJsonParse);
done.resolve(builtResponse);
@ -186,8 +187,13 @@ export let request = async (
// lets handle an error
requestToFire.on('error', (e) => {
console.error(e);
requestToFire.destroy();
});
const result = await done.promise;
return result;
const response = await done.promise;
response.on('error', (err) => {
console.log(err);
response.destroy();
})
return response;
};