fix(core): update

This commit is contained in:
Philipp Kunz 2019-09-08 17:47:30 +02:00
parent 1f408b5123
commit a73c78e54b
4 changed files with 408 additions and 382 deletions

746
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -28,10 +28,10 @@
"form-data": "^2.3.3" "form-data": "^2.3.3"
}, },
"devDependencies": { "devDependencies": {
"@gitzone/tsbuild": "^2.1.8", "@gitzone/tsbuild": "^2.1.17",
"@gitzone/tsrun": "^1.2.5", "@gitzone/tsrun": "^1.2.8",
"@gitzone/tstest": "^1.0.20", "@gitzone/tstest": "^1.0.24",
"@pushrocks/tapbundle": "^3.0.9", "@pushrocks/tapbundle": "^3.0.13",
"@types/node": "^11.13.6", "@types/node": "^11.13.6",
"tslint": "^5.19.0", "tslint": "^5.19.0",
"tslint-config-prettier": "^1.18.0" "tslint-config-prettier": "^1.18.0"

View File

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

View File

@ -62,6 +62,14 @@ const httpAgent = new plugins.http.Agent({
keepAliveMsecs: 600000 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 * a custom https agent to make sure we can set custom keepAlive options for speedy subsequent calls
*/ */
@ -70,6 +78,14 @@ const httpsAgent = new plugins.https.Agent({
keepAliveMsecs: 600000 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 ( export let request = async (
domainArg: string, domainArg: string,
optionsArg: interfaces.ISmartRequestOptions = {}, optionsArg: interfaces.ISmartRequestOptions = {},
@ -80,7 +96,8 @@ export let request = async (
// merge options // merge options
const defaultOptions: interfaces.ISmartRequestOptions = { const defaultOptions: interfaces.ISmartRequestOptions = {
// agent: agent, // agent: agent,
autoJsonParse: true autoJsonParse: true,
keepAlive:true,
}; };
optionsArg = { optionsArg = {
@ -107,7 +124,21 @@ export let request = async (
// lets determine the request module to use // lets determine the request module to use
const requestModule = (() => { 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; optionsArg.agent = httpsAgent;
return plugins.https; return plugins.https;
} else if (parsedUrl.protocol === 'http:') { } else if (parsedUrl.protocol === 'http:') {