mirror of
https://github.com/usebruno/bruno.git
synced 2026-06-29 23:54:24 +00:00
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:
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user