fix(core): update
This commit is contained in:
@ -10,17 +10,17 @@ export const getBinary = async (
|
||||
) => {
|
||||
optionsArg = {
|
||||
...optionsArg,
|
||||
autoJsonParse: false
|
||||
autoJsonParse: false,
|
||||
};
|
||||
const done = plugins.smartpromise.defer();
|
||||
const response = await request(domainArg, optionsArg, true);
|
||||
const data = [];
|
||||
|
||||
response
|
||||
.on('data', function(chunk) {
|
||||
.on('data', function (chunk) {
|
||||
data.push(chunk);
|
||||
})
|
||||
.on('end', function() {
|
||||
.on('end', function () {
|
||||
//at this point data is an array of Buffers
|
||||
//so Buffer.concat() can make us a new Buffer
|
||||
//of all of them together
|
||||
|
@ -31,13 +31,13 @@ const appendFormField = async (formDataArg: plugins.formData, formDataField: IFo
|
||||
);
|
||||
formDataArg.append('file', fileData, {
|
||||
filename: formDataField.fileName ? formDataField.fileName : 'upload.pdf',
|
||||
contentType: 'application/pdf'
|
||||
contentType: 'application/pdf',
|
||||
});
|
||||
break;
|
||||
case 'Buffer':
|
||||
formDataArg.append(formDataField.name, formDataField.payload, {
|
||||
filename: formDataField.fileName ? formDataField.fileName : 'upload.pdf',
|
||||
contentType: formDataField.contentType ? formDataField.contentType : 'application/pdf'
|
||||
contentType: formDataField.contentType ? formDataField.contentType : 'application/pdf',
|
||||
});
|
||||
break;
|
||||
}
|
||||
@ -57,9 +57,9 @@ export const postFormData = async (
|
||||
method: 'POST',
|
||||
headers: {
|
||||
...optionsArg.headers,
|
||||
...form.getHeaders()
|
||||
...form.getHeaders(),
|
||||
},
|
||||
requestBody: form
|
||||
requestBody: form,
|
||||
};
|
||||
|
||||
// lets fire the actual request for sending the formdata
|
||||
|
@ -14,7 +14,7 @@ export const getJson = async (
|
||||
) => {
|
||||
optionsArg.method = 'GET';
|
||||
optionsArg.headers = {
|
||||
...optionsArg.headers
|
||||
...optionsArg.headers,
|
||||
};
|
||||
let response = await request(domainArg, optionsArg);
|
||||
return response;
|
||||
@ -37,7 +37,7 @@ export const postJson = async (
|
||||
// assign the right Content-Type, leaving all other headers in place
|
||||
optionsArg.headers = {
|
||||
...optionsArg.headers,
|
||||
'Content-Type': 'application/json'
|
||||
'Content-Type': 'application/json',
|
||||
};
|
||||
}
|
||||
let response = await request(domainArg, optionsArg);
|
||||
|
@ -14,7 +14,7 @@ const buildUtf8Response = (
|
||||
const done = plugins.smartpromise.defer<IExtendedIncomingMessage>();
|
||||
// Continuously update stream with data
|
||||
let body = '';
|
||||
incomingMessageArg.on('data', chunkArg => {
|
||||
incomingMessageArg.on('data', (chunkArg) => {
|
||||
body += chunkArg;
|
||||
});
|
||||
|
||||
@ -50,7 +50,7 @@ const parseSocketPathAndRoute = (stringToParseArg: string) => {
|
||||
const result = parseRegex.exec(stringToParseArg);
|
||||
return {
|
||||
socketPath: result[1],
|
||||
path: result[2]
|
||||
path: result[2],
|
||||
};
|
||||
};
|
||||
|
||||
@ -65,7 +65,7 @@ const httpAgent = new plugins.agentkeepalive.default();
|
||||
const httpAgentKeepAliveFalse = new plugins.http.Agent({
|
||||
maxFreeSockets: 0,
|
||||
keepAlive: false,
|
||||
keepAliveMsecs: 0
|
||||
keepAliveMsecs: 0,
|
||||
});
|
||||
|
||||
/**
|
||||
@ -79,7 +79,7 @@ const httpsAgent = new plugins.agentkeepalive.HttpsAgent();
|
||||
const httpsAgentKeepAliveFalse = new plugins.https.Agent({
|
||||
maxFreeSockets: 0,
|
||||
keepAlive: false,
|
||||
keepAliveMsecs: 0
|
||||
keepAliveMsecs: 0,
|
||||
});
|
||||
|
||||
export let request = async (
|
||||
@ -94,12 +94,12 @@ export let request = async (
|
||||
const defaultOptions: interfaces.ISmartRequestOptions = {
|
||||
// agent: agent,
|
||||
autoJsonParse: true,
|
||||
keepAlive: true
|
||||
keepAlive: true,
|
||||
};
|
||||
|
||||
optionsArg = {
|
||||
...defaultOptions,
|
||||
...optionsArg
|
||||
...optionsArg,
|
||||
};
|
||||
|
||||
// parse url
|
||||
@ -138,7 +138,7 @@ export let request = async (
|
||||
})() as typeof plugins.https;
|
||||
|
||||
// lets perform the actual request
|
||||
const requestToFire = requestModule.request(optionsArg, async response => {
|
||||
const requestToFire = requestModule.request(optionsArg, async (response) => {
|
||||
if (responseStreamArg) {
|
||||
done.resolve(response);
|
||||
} else {
|
||||
@ -150,7 +150,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) => {
|
||||
requestToFire.end();
|
||||
});
|
||||
} else {
|
||||
@ -167,7 +167,7 @@ export let request = async (
|
||||
}
|
||||
|
||||
// lets handle an error
|
||||
requestToFire.on('error', e => {
|
||||
requestToFire.on('error', (e) => {
|
||||
console.error(e);
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user