Compare commits
9 Commits
Author | SHA1 | Date | |
---|---|---|---|
16b4d168db | |||
cc017a9bbf | |||
2adf7e9ee2 | |||
2303b6da7e | |||
4487579bfd | |||
8d2bbcae2a | |||
deb25a3068 | |||
0a83d8b476 | |||
8e7c730d86 |
@ -10,10 +10,10 @@
|
|||||||
"projectType": "npm",
|
"projectType": "npm",
|
||||||
"module": {
|
"module": {
|
||||||
"githost": "gitlab.com",
|
"githost": "gitlab.com",
|
||||||
"gitscope": "pushrocks",
|
"gitscope": "push.rocks",
|
||||||
"gitrepo": "smartrequest",
|
"gitrepo": "smartrequest",
|
||||||
"description": "dropin replacement for request",
|
"description": "dropin replacement for request",
|
||||||
"npmPackagename": "@pushrocks/smartrequest",
|
"npmPackagename": "@push.rocks/smartrequest",
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
4
package-lock.json
generated
4
package-lock.json
generated
@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartrequest",
|
"name": "@pushrocks/smartrequest",
|
||||||
"version": "2.0.13",
|
"version": "2.0.17",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "@pushrocks/smartrequest",
|
"name": "@pushrocks/smartrequest",
|
||||||
"version": "2.0.13",
|
"version": "2.0.17",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/smartpromise": "^3.1.7",
|
"@pushrocks/smartpromise": "^3.1.7",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartrequest",
|
"name": "@push.rocks/smartrequest",
|
||||||
"version": "2.0.13",
|
"version": "2.0.17",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "dropin replacement for request",
|
"description": "dropin replacement for request",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
@ -25,8 +25,8 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://gitlab.com/pushrocks/smartrequest#README",
|
"homepage": "https://gitlab.com/pushrocks/smartrequest#README",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/smartpromise": "^4.0.2",
|
"@push.rocks/smartpromise": "^4.0.2",
|
||||||
"@pushrocks/smarturl": "^3.0.6",
|
"@push.rocks/smarturl": "^3.0.6",
|
||||||
"agentkeepalive": "^4.3.0",
|
"agentkeepalive": "^4.3.0",
|
||||||
"form-data": "^4.0.0"
|
"form-data": "^4.0.0"
|
||||||
},
|
},
|
||||||
|
32
pnpm-lock.yaml
generated
32
pnpm-lock.yaml
generated
@ -1,12 +1,16 @@
|
|||||||
lockfileVersion: '6.0'
|
lockfileVersion: '6.0'
|
||||||
|
|
||||||
|
settings:
|
||||||
|
autoInstallPeers: true
|
||||||
|
excludeLinksFromLockfile: false
|
||||||
|
|
||||||
dependencies:
|
dependencies:
|
||||||
'@pushrocks/smartpromise':
|
'@push.rocks/smartpromise':
|
||||||
specifier: ^4.0.2
|
specifier: ^4.0.2
|
||||||
version: 4.0.2
|
version: 4.0.3
|
||||||
'@pushrocks/smarturl':
|
'@push.rocks/smarturl':
|
||||||
specifier: ^3.0.6
|
specifier: ^3.0.6
|
||||||
version: 3.0.6
|
version: 3.0.7
|
||||||
agentkeepalive:
|
agentkeepalive:
|
||||||
specifier: ^4.3.0
|
specifier: ^4.3.0
|
||||||
version: 4.3.0
|
version: 4.3.0
|
||||||
@ -311,6 +315,14 @@ packages:
|
|||||||
- utf-8-validate
|
- utf-8-validate
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
|
/@push.rocks/smartpromise@4.0.3:
|
||||||
|
resolution: {integrity: sha512-z3lIso4/6KK3c6NFTVGZ7AOBsGURf8ha3qQtX/OxjZFk5dqS//8PLd0XqghVdIaUlRGmJ7Sfds/efZERWn1tAg==}
|
||||||
|
dev: false
|
||||||
|
|
||||||
|
/@push.rocks/smarturl@3.0.7:
|
||||||
|
resolution: {integrity: sha512-nx4EWjQD9JeO7QVbOsxd1PFeDQYoSQOOOYCZ+r7QWXHLJG52iYzgvJDCQyX6p705HDkYMJWozW2ZzhR22qLKbw==}
|
||||||
|
dev: false
|
||||||
|
|
||||||
/@pushrocks/consolecolor@2.0.1:
|
/@pushrocks/consolecolor@2.0.1:
|
||||||
resolution: {integrity: sha512-iOFCHVeFZ2OywbdwSxVI4/wokkcLrXVdHLgvMmkNhJ220eeLgjNZWx3EJo3vNW3zq5ybCSCUIq0878djBxrWpw==}
|
resolution: {integrity: sha512-iOFCHVeFZ2OywbdwSxVI4/wokkcLrXVdHLgvMmkNhJ220eeLgjNZWx3EJo3vNW3zq5ybCSCUIq0878djBxrWpw==}
|
||||||
dependencies:
|
dependencies:
|
||||||
@ -637,10 +649,6 @@ packages:
|
|||||||
resolution: {integrity: sha512-VeTurbZ1+ZMxBDJk1Y1LV8SN9xLI+oDXKVeCFw41FAGEKOUEqordqFpi6t+7Vhe/TXUZzCVpZ5bXxAxrGf8yTQ==}
|
resolution: {integrity: sha512-VeTurbZ1+ZMxBDJk1Y1LV8SN9xLI+oDXKVeCFw41FAGEKOUEqordqFpi6t+7Vhe/TXUZzCVpZ5bXxAxrGf8yTQ==}
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
/@pushrocks/smartpromise@4.0.2:
|
|
||||||
resolution: {integrity: sha512-bqorOaGXPOuiOSV81luTKrTghg4O4NBRD0zyv7TIqmrMGf4a0uoozaUMp1X8vQdZW+y0gTzUJP9wkzAE6Cci0g==}
|
|
||||||
dev: false
|
|
||||||
|
|
||||||
/@pushrocks/smartpuppeteer@2.0.2:
|
/@pushrocks/smartpuppeteer@2.0.2:
|
||||||
resolution: {integrity: sha512-l3tqnD6Evseofq1avHsMy2FXXEmCd4Z+nm3xmMWS7nWvP9qTbJIn0XguOBaUIAhR8zE53UKPXs5/qBqXVNZDDQ==}
|
resolution: {integrity: sha512-l3tqnD6Evseofq1avHsMy2FXXEmCd4Z+nm3xmMWS7nWvP9qTbJIn0XguOBaUIAhR8zE53UKPXs5/qBqXVNZDDQ==}
|
||||||
dependencies:
|
dependencies:
|
||||||
@ -800,6 +808,7 @@ packages:
|
|||||||
|
|
||||||
/@pushrocks/smarturl@3.0.6:
|
/@pushrocks/smarturl@3.0.6:
|
||||||
resolution: {integrity: sha512-YHWnYE1mm8WIJk1usSXg+kNM7s7ByM+PKApO9cgl0T/oGybjzAJiO3clGNDro4ysP0TD+WuvJuiVue02bErEBQ==}
|
resolution: {integrity: sha512-YHWnYE1mm8WIJk1usSXg+kNM7s7ByM+PKApO9cgl0T/oGybjzAJiO3clGNDro4ysP0TD+WuvJuiVue02bErEBQ==}
|
||||||
|
dev: true
|
||||||
|
|
||||||
/@pushrocks/smartxml@1.0.6:
|
/@pushrocks/smartxml@1.0.6:
|
||||||
resolution: {integrity: sha512-Cy//pxzdpplqE64h9/sAwvAkUBv9t3Nw9v6k2c+erXH779iOtuyGiiyWqgbRTX1wo2CRhMJqWGJx6xd2Ljq5kw==}
|
resolution: {integrity: sha512-Cy//pxzdpplqE64h9/sAwvAkUBv9t3Nw9v6k2c+erXH779iOtuyGiiyWqgbRTX1wo2CRhMJqWGJx6xd2Ljq5kw==}
|
||||||
@ -1339,6 +1348,11 @@ packages:
|
|||||||
- utf-8-validate
|
- utf-8-validate
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
|
/@xmldom/xmldom@0.8.8:
|
||||||
|
resolution: {integrity: sha512-0LNz4EY8B/8xXY86wMrQ4tz6zEHZv9ehFMJPm8u2gq5lQ71cfRKdaKyxfJAx5aUoyzx0qzgURblTisPGgz3d+Q==}
|
||||||
|
engines: {node: '>=10.0.0'}
|
||||||
|
dev: true
|
||||||
|
|
||||||
/accepts@1.3.8:
|
/accepts@1.3.8:
|
||||||
resolution: {integrity: sha512-PYAthTa2m2VKxuvSD3DPC/Gy+U+sOA1LAuT8mkmRuvw+NACSaeXEQ+NHcVF7rONl6qcaxV3Uuemwawk+7+SJLw==}
|
resolution: {integrity: sha512-PYAthTa2m2VKxuvSD3DPC/Gy+U+sOA1LAuT8mkmRuvw+NACSaeXEQ+NHcVF7rONl6qcaxV3Uuemwawk+7+SJLw==}
|
||||||
engines: {node: '>= 0.6'}
|
engines: {node: '>= 0.6'}
|
||||||
@ -3491,6 +3505,8 @@ packages:
|
|||||||
resolution: {integrity: sha512-mXF9AIgnvq1DP/ZM2R28tAfxP2wKZHYa2DjV0R1KCwcqSzm5Iqh1XQq9rdfAt6dp2DuPP0VHZIaCALc2v1cL5A==}
|
resolution: {integrity: sha512-mXF9AIgnvq1DP/ZM2R28tAfxP2wKZHYa2DjV0R1KCwcqSzm5Iqh1XQq9rdfAt6dp2DuPP0VHZIaCALc2v1cL5A==}
|
||||||
engines: {node: '>=14.18.0', npm: '>=6.14.15'}
|
engines: {node: '>=14.18.0', npm: '>=6.14.15'}
|
||||||
hasBin: true
|
hasBin: true
|
||||||
|
dependencies:
|
||||||
|
'@xmldom/xmldom': 0.8.8
|
||||||
dev: true
|
dev: true
|
||||||
bundledDependencies:
|
bundledDependencies:
|
||||||
- '@xmldom/xmldom'
|
- '@xmldom/xmldom'
|
||||||
|
@ -13,13 +13,18 @@ tap.test('should request a JSON document over https', async () => {
|
|||||||
.toEqual(1);
|
.toEqual(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.skip.test('should post a JSON document over http', async () => {
|
tap.test('should post a JSON document over http', async () => {
|
||||||
await expectAsync(smartrequest.postJson('http://md5.jsontest.com/?text=example_text'))
|
await expectAsync(smartrequest.postJson('http://md5.jsontest.com/?text=example_text'))
|
||||||
.property('body')
|
.property('body')
|
||||||
.property('md5')
|
.property('md5')
|
||||||
.toEqual('fa4c6baa0812e5b5c80ed8885e55a8a6');
|
.toEqual('fa4c6baa0812e5b5c80ed8885e55a8a6');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
tap.test('should safe get stuff', async () => {
|
||||||
|
smartrequest.safeGet('http://coffee.link/');
|
||||||
|
smartrequest.safeGet('https://coffee.link/');
|
||||||
|
});
|
||||||
|
|
||||||
tap.skip.test('should deal with unix socks', async () => {
|
tap.skip.test('should deal with unix socks', async () => {
|
||||||
const socketResponse = await smartrequest.request(
|
const socketResponse = await smartrequest.request(
|
||||||
'http://unix:/var/run/docker.sock:/containers/json',
|
'http://unix:/var/run/docker.sock:/containers/json',
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
* autocreated commitinfo by @pushrocks/commitinfo
|
* autocreated commitinfo by @pushrocks/commitinfo
|
||||||
*/
|
*/
|
||||||
export const commitinfo = {
|
export const commitinfo = {
|
||||||
name: '@pushrocks/smartrequest',
|
name: '@push.rocks/smartrequest',
|
||||||
version: '2.0.13',
|
version: '2.0.17',
|
||||||
description: 'dropin replacement for request'
|
description: 'dropin replacement for request'
|
||||||
}
|
}
|
||||||
|
@ -6,4 +6,5 @@ export interface ISmartRequestOptions extends https.RequestOptions {
|
|||||||
requestBody?: any;
|
requestBody?: any;
|
||||||
autoJsonParse?: boolean;
|
autoJsonParse?: boolean;
|
||||||
queryParams?: { [key: string]: string };
|
queryParams?: { [key: string]: string };
|
||||||
|
hardDataCuttingTimeout?: number;
|
||||||
}
|
}
|
||||||
|
@ -7,8 +7,8 @@ import * as path from 'path';
|
|||||||
export { http, https, fs, path };
|
export { http, https, fs, path };
|
||||||
|
|
||||||
// pushrocks scope
|
// pushrocks scope
|
||||||
import * as smartpromise from '@pushrocks/smartpromise';
|
import * as smartpromise from '@push.rocks/smartpromise';
|
||||||
import * as smarturl from '@pushrocks/smarturl';
|
import * as smarturl from '@push.rocks/smarturl';
|
||||||
|
|
||||||
export { smartpromise, smarturl };
|
export { smartpromise, smarturl };
|
||||||
|
|
||||||
|
@ -166,11 +166,18 @@ export let request = async (
|
|||||||
}
|
}
|
||||||
|
|
||||||
// lets perform the actual request
|
// lets perform the actual request
|
||||||
const requestToFire = requestModule.request(optionsArg, async (response) => {
|
const requestToFire = requestModule.request(optionsArg, async (resArg) => {
|
||||||
|
if (optionsArg.hardDataCuttingTimeout) {
|
||||||
|
setTimeout(() => {
|
||||||
|
resArg.destroy();
|
||||||
|
done.reject(new Error('Request timed out'));
|
||||||
|
}, optionsArg.hardDataCuttingTimeout)
|
||||||
|
}
|
||||||
|
|
||||||
if (responseStreamArg) {
|
if (responseStreamArg) {
|
||||||
done.resolve(response as IExtendedIncomingMessage);
|
done.resolve(resArg as IExtendedIncomingMessage);
|
||||||
} else {
|
} else {
|
||||||
const builtResponse = await buildUtf8Response(response, optionsArg.autoJsonParse);
|
const builtResponse = await buildUtf8Response(resArg, optionsArg.autoJsonParse);
|
||||||
done.resolve(builtResponse);
|
done.resolve(builtResponse);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -209,11 +216,13 @@ export let request = async (
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const safeGet = async (urlArg: string) => {
|
export const safeGet = async (urlArg: string) => {
|
||||||
|
const agentToUse = urlArg.startsWith('http://') ? new plugins.http.Agent() : new plugins.https.Agent();
|
||||||
try {
|
try {
|
||||||
const response = await request(urlArg, {
|
const response = await request(urlArg, {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
agent: plugins.http.globalAgent,
|
agent: agentToUse,
|
||||||
timeout: 5000,
|
timeout: 5000,
|
||||||
|
hardDataCuttingTimeout: 5000,
|
||||||
autoJsonParse: false,
|
autoJsonParse: false,
|
||||||
});
|
});
|
||||||
return response;
|
return response;
|
||||||
|
Reference in New Issue
Block a user