Comments (4)
@macedigital I think mirroring the original express-body-parser options, with an extra xmlOptions
property in the object would be best.
{
limit: '1MB',
xmlOptions: {
async: true,
// etc
}
}
Regarding a PR, I've decided not to use this module after all, it turns out that XML parsing with body-parser is actually pretty easy. I've included a code snippet below in case this is useful for anybody.
Regardless, thanks @macedigital for this module!
var express = require('express'),
typeis = require('type-is');
var app = express();
var xmlParseOptions = {
async: false, // Setting to `true` causes issues with exceptions
explicitArray: false,
trim: true,
normalize: true,
normalizeTags: true,
mergeAttrs: true,
charkey: 'value',
attrNameProcessors: [function(attr) {
return '@' + attr;
}]
};
app.use(bodyParser.text({
type: '*/xml',
limit: '1MB'
}));
app.use(function(req, res, next) {
if(!typeis.hasBody(req) || !typeis(req, '*.xml')) {
return next();
}
// Parse as XML
var parser = new xml2js.Parser(xmlParseOptions);
parser.parseString(req.body, function(err, xml) {
if(err) {
err.status = 400;
return next(err);
}
req.body = xml || req.body;
next();
});
});
from express-xml-bodyparser.
Yes, raw-body
integration is planned (soon-ish).
The only thing I'm not 100% sure of is how the option passing should work:
- use a flat-map, pass
raw-body
andxml2js
options in the same config object - use a separate key for passing options for
raw-body
- use a second argument exclusively for
raw-body
options
Actually, option 3 looks like the cleanest solution to me, as it preserves the established api and will never cause issues if either dependency would introduce an option with the same name.
@fiznool let me know what you think. 👍 if you would provide a PR.
from express-xml-bodyparser.
I created a gist https://gist.github.com/macedigital/3799eec3c25a29692a25ee021457b171, so this alternative solution doesn't get lost. If time permits, support for limiting body size will arrive soon.
from express-xml-bodyparser.
Just to mention that I published body-parser-xml a while ago, which fully supports the payload size limiting option, along with every other option that the mainbody-parser
package supports.
from express-xml-bodyparser.
Related Issues (17)
- example app is not working with a simple curl HOT 1
- embedded children aren't displayed properly HOT 1
- xml-body-parser returning errors- HOT 2
- Is it still no longer advisable to have xml2js operate in async=true mode? HOT 3
- Is this works with gzip requests? HOT 2
- support typescript type definition HOT 3
- Error: Non-whitespace before first tag. Line: 0 Column: 1 Char: s HOT 1
- There is no way to get original message in case of error
- Duplicate package xml-bodyparser
- Needs newer version of xml2js to handle malformed xml HOT 1
- Create a option to ignore (or convert) character &
- Snyk Code Analysis - Prototype Pollution Vulnerability HOT 1
- regexp property in index.js undefined HOT 1
- error with xml2js 0.4.5 with malformed xml HOT 7
- Drop support for node v0.8.x HOT 1
- Consider removing shrinkwrap file HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from express-xml-bodyparser.