mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Merge pull request #730 from jthomas/master
Allow HTTP nodes to handle non-UTF8 content.
This commit is contained in:
commit
21b25ffaee
@ -27,17 +27,39 @@ module.exports = function(RED) {
|
||||
var jsonParser = bodyParser.json();
|
||||
var urlencParser = bodyParser.urlencoded({extended:true});
|
||||
var onHeaders = require('on-headers');
|
||||
var typer = require('media-typer');
|
||||
var isUtf8 = require('is-utf8');
|
||||
|
||||
function isMIMETypeText(mimeType) {
|
||||
var parsedType = typer.parse(mimeType)
|
||||
|
||||
if (parsedType.type === "text") {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (parsedType.subtype === "xml" || parsedType.suffix === "xml") {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function rawBodyParser(req, res, next) {
|
||||
if (req._body) { return next(); }
|
||||
req.body = "";
|
||||
req._body = true;
|
||||
|
||||
var textType = isMIMETypeText(req.headers['content-type'])
|
||||
|
||||
getBody(req, {
|
||||
limit: '1mb',
|
||||
length: req.headers['content-length'],
|
||||
encoding: 'utf8'
|
||||
encoding: textType ? "utf8" : null
|
||||
}, function (err, buf) {
|
||||
if (err) { return next(err); }
|
||||
if (!textType && isUtf8(buf)) {
|
||||
buf = buf.toString()
|
||||
}
|
||||
|
||||
req.body = buf;
|
||||
next();
|
||||
});
|
||||
|
@ -45,6 +45,7 @@
|
||||
"uglify-js":"2.4.24",
|
||||
"on-headers":"1.0.1",
|
||||
"is-utf8":"0.2.0",
|
||||
"media-typer": "0.3.0",
|
||||
"fs.notify":"0.0.4",
|
||||
"passport":"0.3.0",
|
||||
"passport-http-bearer":"1.0.1",
|
||||
|
Loading…
Reference in New Issue
Block a user