Compare commits

...

6 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
55c80c1403 1.1.22 2019-08-22 12:38:55 +02:00
7a3e565dbb fix(core): update 2019-08-22 12:38:55 +02:00
4 changed files with 418 additions and 386 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", "name": "@pushrocks/smartrequest",
"version": "1.1.21", "version": "1.1.24",
"private": false, "private": false,
"description": "dropin replacement for request", "description": "dropin replacement for request",
"main": "dist/index.js", "main": "dist/index.js",
@ -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

@ -14,11 +14,11 @@ const buildUtf8Response = (
const done = plugins.smartpromise.defer<IExtendedIncomingMessage>(); const done = plugins.smartpromise.defer<IExtendedIncomingMessage>();
// Continuously update stream with data // Continuously update stream with data
let body = ''; let body = '';
incomingMessageArg.on('data', function(chunkArg) { incomingMessageArg.on('data', (chunkArg) => {
body += chunkArg; body += chunkArg;
}); });
incomingMessageArg.on('end', function() { incomingMessageArg.on('end', () => {
if (autoJsonParse) { if (autoJsonParse) {
try { try {
(incomingMessageArg as IExtendedIncomingMessage).body = JSON.parse(body); (incomingMessageArg as IExtendedIncomingMessage).body = JSON.parse(body);
@ -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({ const httpAgent = new plugins.http.Agent({
keepAlive: true, keepAlive: true,
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
*/
const httpsAgent = new plugins.https.Agent({ const httpsAgent = new plugins.https.Agent({
keepAlive: true, keepAlive: true,
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 = {},
@ -74,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 = {
@ -101,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:') {