mirror of
https://github.com/usebruno/bruno.git
synced 2026-07-08 06:28:33 +00:00
Merge pull request #7939 from usebruno/fix/7642-stream-files-internal
fix: preserve stream-backed file bodies during request interpolation …
This commit is contained in:
@@ -2,6 +2,8 @@ const { interpolate } = require('@usebruno/common');
|
||||
const { each, forOwn, cloneDeep, find } = require('lodash');
|
||||
const { isFormData } = require('@usebruno/common').utils;
|
||||
|
||||
const isBinaryRequestBody = (data) => Buffer.isBuffer(data) || typeof data?.pipe === 'function';
|
||||
|
||||
const getContentType = (headers = {}) => {
|
||||
let contentType = '';
|
||||
forOwn(headers, (value, key) => {
|
||||
@@ -80,7 +82,7 @@ const interpolateVars = (request, envVariables = {}, runtimeVariables = {}, proc
|
||||
|
||||
// Skip body interpolation for GraphQL requests.
|
||||
if (!isGraphqlRequest) {
|
||||
if (contentType.includes('json') && !Buffer.isBuffer(request.data)) {
|
||||
if (contentType.includes('json') && !isBinaryRequestBody(request.data)) {
|
||||
if (typeof request.data === 'string') {
|
||||
if (request?.data?.length) {
|
||||
request.data = _interpolate(request.data, { escapeJSONStrings: true });
|
||||
|
||||
@@ -1,6 +1,25 @@
|
||||
const { describe, it, expect } = require('@jest/globals');
|
||||
const interpolateVars = require('../../src/runner/interpolate-vars');
|
||||
|
||||
describe('interpolate-vars: interpolateVars', () => {
|
||||
it('keeps stream-backed JSON request bodies intact', () => {
|
||||
const streamPayload = {
|
||||
pipe: jest.fn(),
|
||||
path: '/tmp/allocations.json'
|
||||
};
|
||||
const request = {
|
||||
method: 'POST',
|
||||
mode: 'file',
|
||||
url: 'http://api.example/upload',
|
||||
headers: { 'content-type': 'application/json' },
|
||||
data: streamPayload
|
||||
};
|
||||
|
||||
const result = interpolateVars(request, { shouldNotApply: 'value' }, null, null);
|
||||
expect(result.data).toBe(streamPayload);
|
||||
});
|
||||
});
|
||||
|
||||
describe('interpolate-vars: api key header name sidecar', () => {
|
||||
it('interpolates apiKeyHeaderName in lockstep with interpolated header keys', () => {
|
||||
const request = {
|
||||
|
||||
Reference in New Issue
Block a user