feat: apply modified dataBuffer to the response (#6023)

* feat: apply modified dataBuffer to the response

* fix: ensure dataBuffer regeneration only occurs when res.setBody() is called

* refactor: update dataBuffer handling in BrunoResponse
This commit is contained in:
Pragadesh-45
2026-01-12 11:39:26 +05:30
committed by GitHub
parent 33594bdcec
commit 734ee16fe1
2 changed files with 15 additions and 1 deletions

View File

@@ -935,9 +935,9 @@ const registerNetworkIpc = (mainWindow) => {
statusText: response.statusText,
headers: response.headers,
data: response.data,
dataBuffer: response.dataBuffer.toString('base64'),
stream: isResponseStream ? axiosDataStream : null,
cancelTokenUid: cancelTokenUid,
dataBuffer: response.dataBuffer.toString('base64'),
size: Buffer.byteLength(response.dataBuffer),
duration: responseTime ?? 0,
url: response.request ? response.request.protocol + '//' + response.request.host + response.request.path : null,

View File

@@ -55,6 +55,20 @@ class BrunoResponse {
const clonedData = _.cloneDeep(data);
this.res.data = clonedData;
this.body = clonedData;
// Update dataBuffer to match the modified body
if (clonedData === null || clonedData === undefined) {
this.res.dataBuffer = Buffer.from('');
} else if (typeof clonedData === 'string') {
this.res.dataBuffer = Buffer.from(clonedData);
} else {
// For objects, stringify them
try {
this.res.dataBuffer = Buffer.from(JSON.stringify(clonedData));
} catch (e) {
this.res.dataBuffer = Buffer.from('');
}
}
}
// TODO: Refactor: dataBuffer size calculation should be handled in a shared utility so it can be passed and reused across the application