diff --git a/package.json b/package.json index 8e2c2715f..bc1b16f90 100644 --- a/package.json +++ b/package.json @@ -34,5 +34,8 @@ }, "overrides": { "rollup": "3.2.5" + }, + "dependencies": { + "xml-formatter": "^3.3.2" } -} \ No newline at end of file +} diff --git a/packages/bruno-app/src/components/ResponsePane/index.js b/packages/bruno-app/src/components/ResponsePane/index.js index 1648c7080..8847ef6be 100644 --- a/packages/bruno-app/src/components/ResponsePane/index.js +++ b/packages/bruno-app/src/components/ResponsePane/index.js @@ -1,7 +1,7 @@ import React from 'react'; import find from 'lodash/find'; import classnames from 'classnames'; -import { safeStringifyJSON } from 'utils/common'; +import { formatResponse } from 'utils/common'; import { useSelector, useDispatch } from 'react-redux'; import { updateResponsePaneTab } from 'providers/ReduxStore/slices/tabs'; import QueryResult from './QueryResult'; @@ -16,6 +16,7 @@ import TestResults from './TestResults'; import TestResultsLabel from './TestResultsLabel'; import StyledWrapper from './StyledWrapper'; + const ResponsePane = ({ rightPaneWidth, item, collection }) => { const dispatch = useDispatch(); const tabs = useSelector((state) => state.tabs.tabs); @@ -40,7 +41,7 @@ const ResponsePane = ({ rightPaneWidth, item, collection }) => { item={item} collection={collection} width={rightPaneWidth} - value={response.data ? safeStringifyJSON(response.data, true) : ''} + value={response.data ? formatResponse(response): ''} />; } case 'headers': { diff --git a/packages/bruno-app/src/utils/common/index.js b/packages/bruno-app/src/utils/common/index.js index f5b3b2dfb..f11c972d3 100644 --- a/packages/bruno-app/src/utils/common/index.js +++ b/packages/bruno-app/src/utils/common/index.js @@ -1,4 +1,5 @@ import { customAlphabet } from 'nanoid'; +import xmlFormat from 'xml-formatter'; // a customized version of nanoid without using _ and - export const uuid = () => { @@ -50,6 +51,16 @@ export const safeStringifyJSON = (obj, indent=false) => { } } +export const formatResponse = (response) => { + var type = response.headers.find((element) => element[0]=='content-type')[1]; + if(type.includes("json")){ + return safeStringifyJSON(response.data); + }if(type.includes("xml")){ + return xmlFormat(response.data, {collapseContent: true}); + } + return response.data; +} + // Remove any characters that are not alphanumeric, spaces, hyphens, or underscores export const normalizeFileName = (name) => { if (!name) {