fix(core): update
This commit is contained in:
parent
145505b891
commit
db80f2df7e
22797
package-lock.json
generated
22797
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
14
package.json
14
package.json
@ -23,17 +23,17 @@
|
||||
},
|
||||
"homepage": "https://gitlab.com/pushrocks/smartrequest#README",
|
||||
"dependencies": {
|
||||
"@pushrocks/smartpromise": "^3.1.5",
|
||||
"@pushrocks/smartpromise": "^3.1.6",
|
||||
"@pushrocks/smarturl": "^2.0.1",
|
||||
"agentkeepalive": "^4.1.4",
|
||||
"agentkeepalive": "^4.2.0",
|
||||
"form-data": "^4.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@gitzone/tsbuild": "^2.1.25",
|
||||
"@gitzone/tsrun": "^1.2.12",
|
||||
"@gitzone/tstest": "^1.0.54",
|
||||
"@pushrocks/tapbundle": "^3.2.14",
|
||||
"@types/node": "^15.3.0",
|
||||
"@gitzone/tsbuild": "^2.1.29",
|
||||
"@gitzone/tsrun": "^1.2.18",
|
||||
"@gitzone/tstest": "^1.0.64",
|
||||
"@pushrocks/tapbundle": "^4.0.7",
|
||||
"@types/node": "^17.0.18",
|
||||
"tslint": "^6.1.3",
|
||||
"tslint-config-prettier": "^1.18.0"
|
||||
},
|
||||
|
24
test/test.ts
24
test/test.ts
@ -1,31 +1,23 @@
|
||||
import { tap, expect } from '@pushrocks/tapbundle';
|
||||
import { tap, expect, expectAsync } from '@pushrocks/tapbundle';
|
||||
|
||||
import * as smartrequest from '../ts/index';
|
||||
|
||||
tap.test('should request a html document over https', async () => {
|
||||
await expect(smartrequest.getJson('https://encrypted.google.com/'))
|
||||
.to.eventually.property('body')
|
||||
.be.a('string');
|
||||
await expect(smartrequest.getJson('https://encrypted.google.com/'))
|
||||
.to.eventually.property('body')
|
||||
.be.a('string');
|
||||
await expect(smartrequest.getJson('https://encrypted.google.com/'))
|
||||
.to.eventually.property('body')
|
||||
.be.a('string');
|
||||
await expectAsync(smartrequest.getJson('https://encrypted.google.com/')).toHaveProperty('body')
|
||||
});
|
||||
|
||||
tap.test('should request a JSON document over https', async () => {
|
||||
await expect(smartrequest.getJson('https://jsonplaceholder.typicode.com/posts/1'))
|
||||
.to.eventually.property('body')
|
||||
await expectAsync(smartrequest.getJson('https://jsonplaceholder.typicode.com/posts/1'))
|
||||
.property('body')
|
||||
.property('id')
|
||||
.equal(1);
|
||||
.toEqual(1);
|
||||
});
|
||||
|
||||
tap.skip.test('should post a JSON document over http', async () => {
|
||||
await expect(smartrequest.postJson('http://md5.jsontest.com/?text=example_text'))
|
||||
.to.eventually.property('body')
|
||||
await expectAsync(smartrequest.postJson('http://md5.jsontest.com/?text=example_text'))
|
||||
.property('body')
|
||||
.property('md5')
|
||||
.equal('fa4c6baa0812e5b5c80ed8885e55a8a6');
|
||||
.toEqual('fa4c6baa0812e5b5c80ed8885e55a8a6');
|
||||
});
|
||||
|
||||
tap.skip.test('should deal with unix socks', async () => {
|
||||
|
@ -14,10 +14,10 @@ export const getBinary = async (
|
||||
};
|
||||
const done = plugins.smartpromise.defer();
|
||||
const response = await request(domainArg, optionsArg, true);
|
||||
const data = [];
|
||||
const data: Array<Buffer> = [];
|
||||
|
||||
response
|
||||
.on('data', function (chunk) {
|
||||
.on('data', function (chunk: Buffer) {
|
||||
data.push(chunk);
|
||||
})
|
||||
.on('end', function () {
|
||||
|
@ -66,3 +66,32 @@ export const postFormData = async (
|
||||
const response = await request(urlArg, requestOptions);
|
||||
return response;
|
||||
};
|
||||
|
||||
export const postFormDataUrlEncoded = async (
|
||||
urlArg: string,
|
||||
optionsArg: interfaces.ISmartRequestOptions = {},
|
||||
payloadArg: {key: string, content: string}[]
|
||||
) => {
|
||||
const requestOptions = {
|
||||
...optionsArg,
|
||||
method: 'POST',
|
||||
headers: {
|
||||
...optionsArg.headers,
|
||||
'content-type': 'application/x-www-form-urlencoded'
|
||||
}
|
||||
};
|
||||
|
||||
let resultString = '';
|
||||
|
||||
for (const keyContentPair of payloadArg) {
|
||||
if (resultString) {
|
||||
resultString += '&';
|
||||
}
|
||||
resultString += `${encodeURIComponent(keyContentPair.key)}=${encodeURIComponent(keyContentPair.content)}`;
|
||||
}
|
||||
|
||||
|
||||
// lets fire the actual request for sending the formdata
|
||||
const response = await request(urlArg + resultString, requestOptions);
|
||||
return response;
|
||||
};
|
||||
|
@ -158,7 +158,7 @@ export let request = async (
|
||||
// lets write the requestBody
|
||||
if (optionsArg.requestBody) {
|
||||
if (optionsArg.requestBody instanceof plugins.formData) {
|
||||
optionsArg.requestBody.pipe(requestToFire).on('finish', (event) => {
|
||||
optionsArg.requestBody.pipe(requestToFire).on('finish', (event: any) => {
|
||||
requestToFire.end();
|
||||
});
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user