Compare commits

...

9 Commits

Author SHA1 Message Date
fdd1c7cdb3 2.0.18 2023-07-12 00:53:10 +02:00
40f330791f fix(core): update 2023-07-12 00:53:09 +02:00
16b4d168db 2.0.17 2023-07-12 00:24:37 +02:00
cc017a9bbf fix(core): update 2023-07-12 00:24:36 +02:00
2adf7e9ee2 2.0.16 2023-07-12 00:23:26 +02:00
2303b6da7e fix(core): update 2023-07-12 00:23:25 +02:00
4487579bfd switch to new org scheme 2023-07-10 10:17:43 +02:00
8d2bbcae2a 2.0.15 2023-04-19 14:38:28 +02:00
deb25a3068 fix(core): update 2023-04-19 14:38:28 +02:00
9 changed files with 754 additions and 509 deletions

View File

@ -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
View File

@ -1,12 +1,12 @@
{ {
"name": "@pushrocks/smartrequest", "name": "@pushrocks/smartrequest",
"version": "2.0.14", "version": "2.0.18",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "@pushrocks/smartrequest", "name": "@pushrocks/smartrequest",
"version": "2.0.14", "version": "2.0.18",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@pushrocks/smartpromise": "^3.1.7", "@pushrocks/smartpromise": "^3.1.7",

View File

@ -1,6 +1,6 @@
{ {
"name": "@pushrocks/smartrequest", "name": "@push.rocks/smartrequest",
"version": "2.0.14", "version": "2.0.18",
"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"
}, },

1215
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@ -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',

View File

@ -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.14', version: '2.0.18',
description: 'dropin replacement for request' description: 'dropin replacement for request'
} }

View File

@ -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;
} }

View File

@ -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 };

View File

@ -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,12 +216,13 @@ export let request = async (
}; };
export const safeGet = async (urlArg: string) => { export const safeGet = async (urlArg: string) => {
const agentToUse = urlArg.startsWith('http') ? plugins.http.globalAgent : plugins.https.globalAgent; 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: agentToUse, agent: agentToUse,
timeout: 5000, timeout: 5000,
hardDataCuttingTimeout: 5000,
autoJsonParse: false, autoJsonParse: false,
}); });
return response; return response;