Move WRITEFUNCTION definition lower (Fixes #633)

I have no idea why moving this function down works, but it did.
This commit is contained in:
Gregory Schier 2017-11-30 11:06:04 +00:00
parent feecc8f203
commit a0685c882e

View File

@ -471,19 +471,6 @@ export async function _actuallySend (
setOpt(Curl.option.POSTFIELDS, requestBody);
}
let responseBodyBytes = 0;
const responsesDir = pathJoin(app.getPath('userData'), 'responses');
mkdirp.sync(responsesDir);
const responseBodyPath = pathJoin(responsesDir, uuid.v4() + '.response');
const responseBodyWriteStream = fs.createWriteStream(responseBodyPath);
curl.on('end', () => responseBodyWriteStream.end());
curl.on('error', () => responseBodyWriteStream.end());
setOpt(Curl.option.WRITEFUNCTION, (buff: Buffer) => {
responseBodyBytes += buff.length;
responseBodyWriteStream.write(buff);
return buff.length;
});
// Handle Authorization header
if (!hasAuthHeader(headers) && !renderedRequest.authentication.disabled) {
if (renderedRequest.authentication.type === AUTH_BASIC) {
@ -562,6 +549,19 @@ export async function _actuallySend (
.map(h => `${(h.name || '').trim()}: ${h.value}`);
setOpt(Curl.option.HTTPHEADER, headerStrings);
let responseBodyBytes = 0;
const responsesDir = pathJoin(app.getPath('userData'), 'responses');
mkdirp.sync(responsesDir);
const responseBodyPath = pathJoin(responsesDir, uuid.v4() + '.response');
const responseBodyWriteStream = fs.createWriteStream(responseBodyPath);
curl.on('end', () => responseBodyWriteStream.end());
curl.on('error', () => responseBodyWriteStream.end());
setOpt(Curl.option.WRITEFUNCTION, (buff: Buffer) => {
responseBodyBytes += buff.length;
responseBodyWriteStream.write(buff);
return buff.length;
});
// Handle the response ending
curl.on('end', async (_1, _2, rawHeaders) => {
const allCurlHeadersObjects = _parseHeaders(rawHeaders);