mirror of
https://github.com/usebruno/bruno.git
synced 2026-10-12 02:24:01 +00:00
fix(bruno-request): set Buffer bodies from req.setBody as-is under a JSON Content-Type
This commit is contained in:
@@ -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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user