fix(bruno-request): set Buffer bodies from req.setBody as-is under a JSON Content-Type

This commit is contained in:
lohit-bruno
2026-10-06 16:46:09 +05:30
parent 300f100112
commit d195316fa0
2 changed files with 10 additions and 1 deletions
+2 -1
View File
@@ -204,9 +204,10 @@ class BrunoRequest {
* - We set the body property as the data itself
*
* If the user wants to override this behavior, they can pass the raw option as true
* A Buffer is always set as-is, since it already holds the exact bytes to send
*/
setBody(data, options = {}) {
if (options.raw) {
if (options.raw || Buffer.isBuffer(data)) {
this.req.data = data;
this.body = data;
return;
@@ -42,6 +42,14 @@ describe.each(['nodevm', 'quickjs'])('req.setBody() in a pre-request script on %
expect(request.data).toStrictEqual(Buffer.from(BINARY_BYTES));
});
it('keeps every byte of a Buffer body set without options when Content-Type is application/json', async () => {
const request = makeRequest({ headers: { 'content-type': 'application/json' } });
await runRequestScript(runtime, `req.setBody(Buffer.from(${JSON.stringify(BINARY_BYTES)}))`, request);
expect(request.data).toStrictEqual(Buffer.from(BINARY_BYTES));
});
it('keeps only the bytes inside a sliced Buffer body', async () => {
const request = makeRequest();