mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Fix parsing of content-type header
Fixes #2216 This was broken when we switched from media-typer to content-type modules for parsing the content-type header. The content-type header can handle the field with parameters, but does not do the type/sub-type parsing that media-typer does. Our code relied on that extra bit of parsing to correctly identify if the content should be parsed to String or kept as a buffer. The fix restores the use of media-typer, but using the result of the content-type module to make sure it valid
This commit is contained in:
parent
f3fc083330
commit
e315325d91
@ -48,6 +48,7 @@
|
|||||||
"js-yaml": "3.13.1",
|
"js-yaml": "3.13.1",
|
||||||
"json-stringify-safe": "5.0.1",
|
"json-stringify-safe": "5.0.1",
|
||||||
"jsonata": "1.6.4",
|
"jsonata": "1.6.4",
|
||||||
|
"media-typer": "1.1.0",
|
||||||
"memorystore": "1.6.1",
|
"memorystore": "1.6.1",
|
||||||
"mime": "2.4.2",
|
"mime": "2.4.2",
|
||||||
"mqtt": "2.18.8",
|
"mqtt": "2.18.8",
|
||||||
|
@ -23,6 +23,7 @@ module.exports = function(RED) {
|
|||||||
var cors = require('cors');
|
var cors = require('cors');
|
||||||
var onHeaders = require('on-headers');
|
var onHeaders = require('on-headers');
|
||||||
var typer = require('content-type');
|
var typer = require('content-type');
|
||||||
|
var mediaTyper = require('media-typer');
|
||||||
var isUtf8 = require('is-utf8');
|
var isUtf8 = require('is-utf8');
|
||||||
var hashSum = require("hash-sum");
|
var hashSum = require("hash-sum");
|
||||||
|
|
||||||
@ -36,18 +37,22 @@ module.exports = function(RED) {
|
|||||||
var checkUTF = false;
|
var checkUTF = false;
|
||||||
|
|
||||||
if (req.headers['content-type']) {
|
if (req.headers['content-type']) {
|
||||||
var parsedType = typer.parse(req.headers['content-type'])
|
var contentType = typer.parse(req.headers['content-type'])
|
||||||
if (parsedType.type === "text") {
|
if (contentType.type) {
|
||||||
isText = true;
|
var parsedType = mediaTyper.parse(contentType.type);
|
||||||
} else if (parsedType.subtype === "xml" || parsedType.suffix === "xml") {
|
if (parsedType.type === "text") {
|
||||||
isText = true;
|
isText = true;
|
||||||
} else if (parsedType.type !== "application") {
|
} else if (parsedType.subtype === "xml" || parsedType.suffix === "xml") {
|
||||||
isText = false;
|
isText = true;
|
||||||
} else if (parsedType.subtype !== "octet-stream") {
|
} else if (parsedType.type !== "application") {
|
||||||
checkUTF = true;
|
isText = false;
|
||||||
} else {
|
} else if (parsedType.subtype !== "octet-stream") {
|
||||||
// applicatino/octet-stream
|
checkUTF = true;
|
||||||
isText = false;
|
} else {
|
||||||
|
// applicatino/octet-stream
|
||||||
|
isText = false;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
"https-proxy-agent": "2.2.1",
|
"https-proxy-agent": "2.2.1",
|
||||||
"is-utf8": "0.2.1",
|
"is-utf8": "0.2.1",
|
||||||
"js-yaml": "3.13.1",
|
"js-yaml": "3.13.1",
|
||||||
|
"media-typer": "1.1.0",
|
||||||
"mqtt": "2.18.8",
|
"mqtt": "2.18.8",
|
||||||
"multer": "1.4.1",
|
"multer": "1.4.1",
|
||||||
"mustache": "3.0.1",
|
"mustache": "3.0.1",
|
||||||
|
Loading…
Reference in New Issue
Block a user