mirror of
https://github.com/usebruno/bruno.git
synced 2026-06-27 06:34:06 +00:00
Feat: Support multipart/mixed (#7155)
* feat(): support multipart mixed fix: support vars interpolation on mixed multi-part Update packages/bruno-electron/src/ipc/network/interpolate-vars.js Co-authored-by: Timon <39559178+Its-treason@users.noreply.github.com> refactor: use startsWith feat: best effort for other multipart/* contentypes * feat: enhance variable interpolation for multipart requests - Updated `interpolateVars` function to support interpolation in multipart/form-data and multipart/mixed requests. - Added handling for empty multipart arrays and parts with missing or undefined values. - Improved type checks for content types to ensure proper interpolation behavior. Includes new tests to validate the interpolation functionality for multipart requests. * fix: normalize error handling in sendRequest and improve test reliability --------- Co-authored-by: Alfonso Presa <alfonso-presa@users.noreply.github.com>
This commit is contained in:
@@ -582,12 +582,22 @@ const registerNetworkIpc = (mainWindow) => {
|
||||
// if `data` is of string type - return as-is (assumes already encoded)
|
||||
}
|
||||
|
||||
if (contentTypeHeader && request.headers[contentTypeHeader] === 'multipart/form-data') {
|
||||
if (contentTypeHeader && contentTypeHeader.startsWith('multipart/')) {
|
||||
if (!isFormData(request.data)) {
|
||||
request._originalMultipartData = request.data;
|
||||
request.collectionPath = collectionPath;
|
||||
let form = createFormData(request.data, collectionPath);
|
||||
request.data = form;
|
||||
if (contentTypeHeader !== 'multipart/form-data') {
|
||||
// Patch: Axios leverages getHeaders method to get the headers so FormData should be monkey patched
|
||||
const formHeaders = form.getHeaders();
|
||||
const ct = contentTypeHeader;
|
||||
formHeaders['content-type'] = `${ct}; boundary=${form.getBoundary()}`;
|
||||
form.getHeaders = function () {
|
||||
return formHeaders;
|
||||
};
|
||||
}
|
||||
|
||||
extend(request.headers, form.getHeaders());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,11 +76,10 @@ const interpolateVars = (request, envVariables = {}, runtimeVariables = {}, proc
|
||||
const contentType = getContentType(request.headers);
|
||||
const isGraphqlRequest = request.mode === 'graphql';
|
||||
|
||||
if (isGrpcRequest) {
|
||||
// gRPC: interpolate entire body (JSON message template and any other keys).
|
||||
if (isGrpcRequest && request.body) {
|
||||
const jsonDoc = JSON.stringify(request.body);
|
||||
const parsed = _interpolate(jsonDoc, {
|
||||
escapeJSONStrings: true
|
||||
});
|
||||
const parsed = _interpolate(jsonDoc, { escapeJSONStrings: true });
|
||||
request.body = JSON.parse(parsed);
|
||||
}
|
||||
// Interpolate WebSocket message body
|
||||
@@ -88,15 +87,11 @@ const interpolateVars = (request, envVariables = {}, runtimeVariables = {}, proc
|
||||
if (isWsRequest && request.body && request.body.ws && Array.isArray(request.body.ws)) {
|
||||
request.body.ws.forEach((message) => {
|
||||
if (message && message.content) {
|
||||
// Try to detect if content is JSON for proper escaping
|
||||
let isJson = false;
|
||||
try {
|
||||
JSON.parse(message.content);
|
||||
isJson = true;
|
||||
} catch (e) {
|
||||
// Not JSON, treat as regular string
|
||||
}
|
||||
|
||||
} catch (e) {}
|
||||
message.content = _interpolate(message.content, {
|
||||
escapeJSONStrings: isJson
|
||||
});
|
||||
@@ -138,7 +133,7 @@ const interpolateVars = (request, envVariables = {}, runtimeVariables = {}, proc
|
||||
value: _interpolate(d?.value)
|
||||
}));
|
||||
}
|
||||
} else if (contentType === 'multipart/form-data') {
|
||||
} else if (contentType.startsWith('multipart/')) {
|
||||
if (Array.isArray(request?.data) && !isFormData(request.data)) {
|
||||
try {
|
||||
request.data = request?.data?.map((d) => ({
|
||||
|
||||
Reference in New Issue
Block a user