mirror of
https://github.com/usebruno/bruno.git
synced 2026-06-29 15:44:13 +00:00
Fix: XML body-parser in testbench server is giving error
This commit is contained in:
@@ -29,8 +29,8 @@ const saveRawBody = (req, res, buf) => {
|
||||
app.use(bodyParser.json({ verify: saveRawBody }));
|
||||
app.use(bodyParser.urlencoded({ extended: true, verify: saveRawBody }));
|
||||
app.use(bodyParser.text({ verify: saveRawBody }));
|
||||
app.use(xmlParser());
|
||||
app.use(express.raw({ type: '*/*', limit: '100mb', verify: saveRawBody }));
|
||||
app.use(xmlParser());
|
||||
|
||||
formDataParser.init(app, express);
|
||||
|
||||
|
||||
@@ -4,23 +4,18 @@ const xmlParser = () => {
|
||||
const parser = new XMLParser({
|
||||
ignoreAttributes: false,
|
||||
allowBooleanAttributes: true,
|
||||
attributeNamePrefix: '',
|
||||
isArray: (name, jpath, isLeafNode) => isLeafNode,
|
||||
});
|
||||
|
||||
return (req, res, next) => {
|
||||
if (req.is('application/xml') || req.is('text/xml')) {
|
||||
let data = '';
|
||||
req.setEncoding('utf8');
|
||||
req.on('data', (chunk) => {
|
||||
data += chunk;
|
||||
});
|
||||
req.on('end', () => {
|
||||
try {
|
||||
req.body = parser.parse(data);
|
||||
next();
|
||||
} catch (err) {
|
||||
res.status(400).send('Invalid XML');
|
||||
}
|
||||
});
|
||||
try {
|
||||
req.body = parser.parse(req.rawBody);
|
||||
next();
|
||||
} catch (err) {
|
||||
res.status(400).send('Invalid XML');
|
||||
}
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user