Skip to content

Commit d680f97

Browse files
authored
Merge pull request #13 from Equals182/remove-type-checking-on-type-check-option
Remove type checking on type check option
2 parents f8a6980 + a0e89a4 commit d680f97

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ Controls the maximum request body size. If this is a number, then the value spec
6767

6868
#### type
6969

70-
The expected `Content-Type` of the XML request to be parsed. Overrides the default content types, can be a String or Array of Strings.
70+
The type option is used to determine what media type the middleware will parse. This option can be a string, array of strings, or a function. If not a function, type option is passed directly to the type-is library and this can be an extension name (like xml), a mime type (like application/xml), or a mime type with a wildcard (like */* or */xml). If a function, the type option is called as fn(req) and the request is parsed if it returns a truthy value. Defaults to `['*/xml', '+xml']`.
7171

7272
#### verify
7373

index.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ module.exports = function(bodyParser) {
1515
options = options || {};
1616

1717
options.type = options.type || DEFAULT_TYPES;
18-
if(!Array.isArray(options.type)) {
19-
options.type = [options.type];
20-
}
2118

2219
const textParser = bodyParser.text(options);
2320
return function xmlParser(req, res, next) {

test.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ describe('XML Body Parser', function() {
5555
});
5656

5757
it('should accept xmlParseOptions', function(done) {
58-
createServer({
58+
createServer({
5959
xmlParseOptions: {
6060
normalize: true, // Trim whitespace inside text nodes
6161
normalizeTags: true, // Transform tags to lowercase
@@ -91,6 +91,16 @@ describe('XML Body Parser', function() {
9191
.expect(200, { parsed: { customer: { name: ['Bob'] } } }, done);
9292
});
9393

94+
it('should accept custom ContentType as function', function(done) {
95+
createServer({
96+
type: function() { return true }
97+
});
98+
request(app)
99+
.post('/')
100+
.send('<customer><name>Bob</name></customer>')
101+
.expect(200, { parsed: { customer: { name: ['Bob'] } } }, done);
102+
});
103+
94104
it('should ignore non-XML', function(done) {
95105
createServer();
96106
request(app)

0 commit comments

Comments
 (0)