fix(core): update
This commit is contained in:
@ -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 {
|
||||
|
Reference in New Issue
Block a user