Compare commits

..

4 Commits

Author SHA1 Message Date
16a97a420c 1.1.24 2019-09-08 17:47:31 +02:00
a73c78e54b fix(core): update 2019-09-08 17:47:30 +02:00
1f408b5123 1.1.23 2019-08-22 12:40:19 +02:00
284f4967f4 fix(core): update 2019-08-22 12:40:19 +02:00
4 changed files with 416 additions and 384 deletions

748
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{
"name": "@pushrocks/smartrequest",
"version": "1.1.22",
"version": "1.1.24",
"private": false,
"description": "dropin replacement for request",
"main": "dist/index.js",
@ -28,10 +28,10 @@
"form-data": "^2.3.3"
},
"devDependencies": {
"@gitzone/tsbuild": "^2.1.8",
"@gitzone/tsrun": "^1.2.5",
"@gitzone/tstest": "^1.0.20",
"@pushrocks/tapbundle": "^3.0.9",
"@gitzone/tsbuild": "^2.1.17",
"@gitzone/tsrun": "^1.2.8",
"@gitzone/tstest": "^1.0.24",
"@pushrocks/tapbundle": "^3.0.13",
"@types/node": "^11.13.6",
"tslint": "^5.19.0",
"tslint-config-prettier": "^1.18.0"

View File

@ -2,6 +2,7 @@ import * as plugins from './smartrequest.plugins';
import * as https from 'https';
export interface ISmartRequestOptions extends https.RequestOptions {
keepAlive?: boolean;
requestBody?: any;
autoJsonParse?: boolean;
}

View File

@ -54,16 +54,38 @@ 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({
keepAlive: true,
keepAliveMsecs: 600000
});
/**
* a custom http agent to make sure we can set custom keepAlive options for speedy subsequent calls
*/
const httpAgentKeepAliveFalse = new plugins.http.Agent({
keepAlive: false,
keepAliveMsecs: 600000
});
/**
* a custom https agent to make sure we can set custom keepAlive options for speedy subsequent calls
*/
const httpsAgent = new plugins.https.Agent({
keepAlive: true,
keepAliveMsecs: 600000
});
/**
* a custom https agent to make sure we can set custom keepAlive options for speedy subsequent calls
*/
const httpsAgentKeepAliveFalse = new plugins.https.Agent({
keepAlive: false,
keepAliveMsecs: 600000
});
export let request = async (
domainArg: string,
optionsArg: interfaces.ISmartRequestOptions = {},
@ -74,7 +96,8 @@ export let request = async (
// merge options
const defaultOptions: interfaces.ISmartRequestOptions = {
// agent: agent,
autoJsonParse: true
autoJsonParse: true,
keepAlive:true,
};
optionsArg = {
@ -101,7 +124,21 @@ export let request = async (
// lets determine the request module to use
const requestModule = (() => {
if (parsedUrl.protocol === 'https:') {
switch (true) {
case parsedUrl.protocol === 'https:' && optionsArg.keepAlive:
optionsArg.agent = httpsAgent;
return plugins.https;
case parsedUrl.protocol === 'https:' && !optionsArg.keepAlive:
optionsArg.agent = httpsAgentKeepAliveFalse;
return plugins.https;
case parsedUrl.protocol === 'http:' && optionsArg.keepAlive:
optionsArg.agent = httpAgent;
return plugins.http;
case parsedUrl.protocol === 'http:' && !optionsArg.keepAlive:
optionsArg.agent = httpAgentKeepAliveFalse;
return plugins.http;
}
if () {
optionsArg.agent = httpsAgent;
return plugins.https;
} else if (parsedUrl.protocol === 'http:') {