fix(core): update
This commit is contained in:
@ -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;
|
||||
}
|
||||
|
@ -62,6 +62,14 @@ const httpAgent = new plugins.http.Agent({
|
||||
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
|
||||
*/
|
||||
@ -70,6 +78,14 @@ const httpsAgent = new plugins.https.Agent({
|
||||
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 = {},
|
||||
@ -80,7 +96,8 @@ export let request = async (
|
||||
// merge options
|
||||
const defaultOptions: interfaces.ISmartRequestOptions = {
|
||||
// agent: agent,
|
||||
autoJsonParse: true
|
||||
autoJsonParse: true,
|
||||
keepAlive:true,
|
||||
};
|
||||
|
||||
optionsArg = {
|
||||
@ -107,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:') {
|
||||
|
Reference in New Issue
Block a user