Compare commits
9 Commits
Author | SHA1 | Date | |
---|---|---|---|
78737c24df | |||
6e276eda00 | |||
021d26a23a | |||
c9c8a1234c | |||
dffabd905f | |||
36f2707141 | |||
b00d674b6f | |||
b09598d465 | |||
acc7b2d46f |
@ -38,11 +38,11 @@ snyk:
|
|||||||
# test stage
|
# test stage
|
||||||
# ====================
|
# ====================
|
||||||
|
|
||||||
testLTS:
|
testStable:
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci node install lts
|
- npmci node install stable
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci npm test
|
- npmci npm test
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
@ -100,7 +100,7 @@ trigger:
|
|||||||
pages:
|
pages:
|
||||||
image: hosttoday/ht-docker-dbase:npmci
|
image: hosttoday/ht-docker-dbase:npmci
|
||||||
services:
|
services:
|
||||||
- docker:18-dind
|
- docker:stable-dind
|
||||||
stage: metadata
|
stage: metadata
|
||||||
script:
|
script:
|
||||||
- npmci command npm install -g @gitzone/tsdoc
|
- npmci command npm install -g @gitzone/tsdoc
|
||||||
|
2
package-lock.json
generated
2
package-lock.json
generated
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartrequest",
|
"name": "@pushrocks/smartrequest",
|
||||||
"version": "1.1.24",
|
"version": "1.1.29",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartrequest",
|
"name": "@pushrocks/smartrequest",
|
||||||
"version": "1.1.24",
|
"version": "1.1.29",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "dropin replacement for request",
|
"description": "dropin replacement for request",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import * as formData from 'form-data';
|
import formData from 'form-data';
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import * as http from 'http';
|
import * as http from 'http';
|
||||||
import * as https from 'https';
|
import * as https from 'https';
|
||||||
|
@ -14,7 +14,7 @@ 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', (chunkArg) => {
|
incomingMessageArg.on('data', chunkArg => {
|
||||||
body += chunkArg;
|
body += chunkArg;
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -66,8 +66,9 @@ const httpAgent = new plugins.http.Agent({
|
|||||||
* a custom http agent to make sure we can set custom keepAlive options for speedy subsequent calls
|
* a custom http agent to make sure we can set custom keepAlive options for speedy subsequent calls
|
||||||
*/
|
*/
|
||||||
const httpAgentKeepAliveFalse = new plugins.http.Agent({
|
const httpAgentKeepAliveFalse = new plugins.http.Agent({
|
||||||
|
maxFreeSockets: 0,
|
||||||
keepAlive: false,
|
keepAlive: false,
|
||||||
keepAliveMsecs: 600000
|
keepAliveMsecs: 0
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -82,8 +83,9 @@ const httpsAgent = new plugins.https.Agent({
|
|||||||
* 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
|
||||||
*/
|
*/
|
||||||
const httpsAgentKeepAliveFalse = new plugins.https.Agent({
|
const httpsAgentKeepAliveFalse = new plugins.https.Agent({
|
||||||
|
maxFreeSockets: 0,
|
||||||
keepAlive: false,
|
keepAlive: false,
|
||||||
keepAliveMsecs: 600000
|
keepAliveMsecs: 0
|
||||||
});
|
});
|
||||||
|
|
||||||
export let request = async (
|
export let request = async (
|
||||||
@ -97,7 +99,7 @@ export let request = async (
|
|||||||
const defaultOptions: interfaces.ISmartRequestOptions = {
|
const defaultOptions: interfaces.ISmartRequestOptions = {
|
||||||
// agent: agent,
|
// agent: agent,
|
||||||
autoJsonParse: true,
|
autoJsonParse: true,
|
||||||
keepAlive:true,
|
keepAlive: true
|
||||||
};
|
};
|
||||||
|
|
||||||
optionsArg = {
|
optionsArg = {
|
||||||
@ -128,42 +130,40 @@ export let request = async (
|
|||||||
case parsedUrl.protocol === 'https:' && optionsArg.keepAlive:
|
case parsedUrl.protocol === 'https:' && optionsArg.keepAlive:
|
||||||
optionsArg.agent = httpsAgent;
|
optionsArg.agent = httpsAgent;
|
||||||
return plugins.https;
|
return plugins.https;
|
||||||
case parsedUrl.protocol === 'https:' && !optionsArg.keepAlive:
|
case parsedUrl.protocol === 'https:' && (!optionsArg.keepAlive):
|
||||||
optionsArg.agent = httpsAgentKeepAliveFalse;
|
optionsArg.agent = httpsAgentKeepAliveFalse;
|
||||||
return plugins.https;
|
return plugins.https;
|
||||||
case parsedUrl.protocol === 'http:' && optionsArg.keepAlive:
|
case parsedUrl.protocol === 'http:' && optionsArg.keepAlive:
|
||||||
optionsArg.agent = httpAgent;
|
optionsArg.agent = httpAgent;
|
||||||
return plugins.http;
|
return plugins.http;
|
||||||
case parsedUrl.protocol === 'http:' && !optionsArg.keepAlive:
|
case parsedUrl.protocol === 'http:' && (!optionsArg.keepAlive):
|
||||||
optionsArg.agent = httpAgentKeepAliveFalse;
|
optionsArg.agent = httpAgentKeepAliveFalse;
|
||||||
return plugins.http;
|
return plugins.http;
|
||||||
}
|
}
|
||||||
if () {
|
|
||||||
optionsArg.agent = httpsAgent;
|
|
||||||
return plugins.https;
|
|
||||||
} else if (parsedUrl.protocol === 'http:') {
|
|
||||||
optionsArg.agent = httpAgent;
|
|
||||||
return plugins.http;
|
|
||||||
} else {
|
|
||||||
throw new Error(`unsupported protocol: ${parsedUrl.protocol}`);
|
|
||||||
}
|
|
||||||
})() as typeof plugins.https;
|
})() as typeof plugins.https;
|
||||||
|
|
||||||
// lets perform the actual request
|
// lets perform the actual request
|
||||||
const requestToFire = requestModule.request(optionsArg);
|
const requestToFire = requestModule.request(optionsArg, async response => {
|
||||||
|
if (streamArg) {
|
||||||
|
done.resolve(response);
|
||||||
|
} else {
|
||||||
|
const builtResponse = await buildUtf8Response(response, optionsArg.autoJsonParse);
|
||||||
|
done.resolve(builtResponse);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// lets write the requestBody
|
// lets write the requestBody
|
||||||
if (optionsArg.requestBody) {
|
if (optionsArg.requestBody) {
|
||||||
if (!(optionsArg.requestBody instanceof plugins.formData)) {
|
if (optionsArg.requestBody instanceof plugins.formData) {
|
||||||
|
optionsArg.requestBody.pipe(requestToFire).on('finish', event => {
|
||||||
|
requestToFire.end();
|
||||||
|
});
|
||||||
|
} else {
|
||||||
if (typeof optionsArg.requestBody !== 'string') {
|
if (typeof optionsArg.requestBody !== 'string') {
|
||||||
optionsArg.requestBody = JSON.stringify(optionsArg.requestBody);
|
optionsArg.requestBody = JSON.stringify(optionsArg.requestBody);
|
||||||
}
|
}
|
||||||
requestToFire.write(optionsArg.requestBody);
|
requestToFire.write(optionsArg.requestBody);
|
||||||
requestToFire.end();
|
requestToFire.end();
|
||||||
} else if (optionsArg.requestBody instanceof plugins.formData) {
|
|
||||||
optionsArg.requestBody.pipe(requestToFire).on('finish', event => {
|
|
||||||
requestToFire.end();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
requestToFire.end();
|
requestToFire.end();
|
||||||
@ -174,16 +174,6 @@ export let request = async (
|
|||||||
console.error(e);
|
console.error(e);
|
||||||
});
|
});
|
||||||
|
|
||||||
// lets handle the response
|
|
||||||
requestToFire.on('response', async response => {
|
|
||||||
if (streamArg) {
|
|
||||||
done.resolve(response);
|
|
||||||
} else {
|
|
||||||
const builtResponse = await buildUtf8Response(response, optionsArg.autoJsonParse);
|
|
||||||
done.resolve(builtResponse);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
const result = await done.promise;
|
const result = await done.promise;
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user