mirror of
https://github.com/usebruno/bruno.git
synced 2026-07-01 08:34:07 +00:00
* Fix: Revert selective JSON parsing where string response is not parsed - Revert "Merge pull request #3706 from Pragadesh-45/fix/response-format-updates" -e897dc1eb0- Revert "Merge pull request #3676 from pooja-bruno/fix/string-json-response" -1f2bee1f90* Fix: Revert interpreting Assert RHS-value wrapped in quotes literally - Revert "Merge pull request #3806 from Pragadesh-45/fix/handle-assert-results" -63d3cb380d- Revert "Merge pull request #3805 from Pragadesh-45/fix/handle-assert-results" -6abd063749* Fix: Inconsistent JSON formatting in preview when encoded value is a string * Fix: Prettify JSON for Res-preview without parsing to avoid JS specific roundings * Fix(testbench): req.body is always Buffer after the binary req body related changes * Added `/api/echo/custom` where response can be configured using request itself * Added tests for validating Assert and Response-preview Co-authored-by: Pragadesh-45 <temporaryg7904@gmail.com> * Handle char-encoding in Response-preview and added more tests * Updated API endpoint in tests to use httpfaker api * QuickJS (Safe Mode) exec logic to handle template literals similar to Developer Mode * Safe Mode bru.runRequest to return statusText similar to Developer Mode --------- Co-authored-by: ramki-bruno <ramki@usebruno.com> Co-authored-by: Anoop M D <anoop.md1421@gmail.com>
78 lines
1.8 KiB
JavaScript
78 lines
1.8 KiB
JavaScript
const express = require('express');
|
|
const router = express.Router();
|
|
|
|
router.post('/json', (req, res) => {
|
|
return res.json(req.body);
|
|
});
|
|
|
|
router.post('/text', (req, res) => {
|
|
res.setHeader('Content-Type', 'text/plain');
|
|
return res.send(req.body);
|
|
});
|
|
|
|
router.post('/xml-parsed', (req, res) => {
|
|
return res.send(req.body);
|
|
});
|
|
|
|
router.post('/xml-raw', (req, res) => {
|
|
res.setHeader('Content-Type', 'application/xml');
|
|
return res.send(req.rawBody);
|
|
});
|
|
|
|
router.post('/bin', (req, res) => {
|
|
const rawBody = req.body;
|
|
|
|
if (!rawBody || rawBody.length === 0) {
|
|
return res.status(400).send('No data received');
|
|
}
|
|
|
|
res.set('Content-Type', req.headers['content-type'] || 'application/octet-stream');
|
|
res.send(rawBody);
|
|
});
|
|
|
|
router.get('/bom-json-test', (req, res) => {
|
|
const jsonData = {
|
|
message: 'Hello!',
|
|
success: true
|
|
};
|
|
const jsonString = JSON.stringify(jsonData);
|
|
const bom = '\uFEFF';
|
|
const jsonWithBom = bom + jsonString;
|
|
res.set('Content-Type', 'application/json; charset=utf-8');
|
|
return res.send(jsonWithBom);
|
|
});
|
|
|
|
router.get('/iso-enc', (req, res) => {
|
|
res.set('Content-Type', 'text/plain; charset=ISO-8859-1');
|
|
const responseText = 'éçà';
|
|
return res.send(Buffer.from(responseText, 'latin1'));
|
|
});
|
|
|
|
router.post("/custom", (req, res) => {
|
|
const { headers, content, contentBase64, contentJSON, type } = req.body || {};
|
|
|
|
res._headers = {};
|
|
|
|
if (type) {
|
|
res.setHeader('Content-Type', type);
|
|
}
|
|
|
|
if (headers && typeof headers === 'object') {
|
|
Object.entries(headers).forEach(([key, value]) => {
|
|
res.setHeader(key, value);
|
|
});
|
|
}
|
|
|
|
if (contentBase64) {
|
|
res.write(Buffer.from(contentBase64, 'base64'));
|
|
} else if (contentJSON !== undefined) {
|
|
res.write(JSON.stringify(contentJSON));
|
|
} else if (content !== undefined) {
|
|
res.write(content);
|
|
}
|
|
|
|
return res.end();
|
|
});
|
|
|
|
module.exports = router;
|