fix(core): update
This commit is contained in:
parent
c9c8a1234c
commit
021d26a23a
@ -143,20 +143,27 @@ export let request = async (
|
|||||||
})() as typeof plugins.https;
|
})() as typeof plugins.https;
|
||||||
|
|
||||||
// lets perform the actual request
|
// lets perform the actual request
|
||||||
const requestToFire = requestModule.request(optionsArg);
|
const requestToFire = requestModule.request(optionsArg, async response => {
|
||||||
|
if (streamArg) {
|
||||||
|
done.resolve(response);
|
||||||
|
} else {
|
||||||
|
const builtResponse = await buildUtf8Response(response, optionsArg.autoJsonParse);
|
||||||
|
done.resolve(builtResponse);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// lets write the requestBody
|
// lets write the requestBody
|
||||||
if (optionsArg.requestBody) {
|
if (optionsArg.requestBody) {
|
||||||
if (!(optionsArg.requestBody instanceof plugins.formData)) {
|
if (optionsArg.requestBody instanceof plugins.formData) {
|
||||||
|
optionsArg.requestBody.pipe(requestToFire).on('finish', event => {
|
||||||
|
requestToFire.end();
|
||||||
|
});
|
||||||
|
} else {
|
||||||
if (typeof optionsArg.requestBody !== 'string') {
|
if (typeof optionsArg.requestBody !== 'string') {
|
||||||
optionsArg.requestBody = JSON.stringify(optionsArg.requestBody);
|
optionsArg.requestBody = JSON.stringify(optionsArg.requestBody);
|
||||||
}
|
}
|
||||||
requestToFire.write(optionsArg.requestBody);
|
requestToFire.write(optionsArg.requestBody);
|
||||||
requestToFire.end();
|
requestToFire.end();
|
||||||
} else if (optionsArg.requestBody instanceof plugins.formData) {
|
|
||||||
optionsArg.requestBody.pipe(requestToFire).on('finish', event => {
|
|
||||||
requestToFire.end();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
requestToFire.end();
|
requestToFire.end();
|
||||||
@ -167,16 +174,6 @@ export let request = async (
|
|||||||
console.error(e);
|
console.error(e);
|
||||||
});
|
});
|
||||||
|
|
||||||
// lets handle the response
|
|
||||||
requestToFire.on('response', async response => {
|
|
||||||
if (streamArg) {
|
|
||||||
done.resolve(response);
|
|
||||||
} else {
|
|
||||||
const builtResponse = await buildUtf8Response(response, optionsArg.autoJsonParse);
|
|
||||||
done.resolve(builtResponse);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
const result = await done.promise;
|
const result = await done.promise;
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user