fix(core): update

This commit is contained in:
2022-02-15 18:53:02 +01:00
parent 145505b891
commit db80f2df7e
6 changed files with 18984 additions and 3886 deletions

View File

@ -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 () {

View File

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

View File

@ -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 {