mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Add guard against the http-request buffer fix being reverted
This commit is contained in:
parent
f54f863611
commit
0a6ff900da
@ -165,14 +165,20 @@ module.exports = function(RED) {
|
|||||||
// See https://github.com/nodejs/node/issues/6038
|
// See https://github.com/nodejs/node/issues/6038
|
||||||
res.setEncoding(null);
|
res.setEncoding(null);
|
||||||
delete res._readableState.decoder;
|
delete res._readableState.decoder;
|
||||||
|
|
||||||
msg.statusCode = res.statusCode;
|
msg.statusCode = res.statusCode;
|
||||||
msg.headers = res.headers;
|
msg.headers = res.headers;
|
||||||
msg.responseUrl = res.responseUrl;
|
msg.responseUrl = res.responseUrl;
|
||||||
msg.payload = [];
|
msg.payload = [];
|
||||||
|
|
||||||
// msg.url = url; // revert when warning above finally removed
|
// msg.url = url; // revert when warning above finally removed
|
||||||
res.on('data',function(chunk) {
|
res.on('data',function(chunk) {
|
||||||
|
if (!Buffer.isBuffer(chunk)) {
|
||||||
|
// if the 'setEncoding(null)' fix above stops working in
|
||||||
|
// a new Node.js release, throw a noisy error so we know
|
||||||
|
// about it.
|
||||||
|
throw new Error("HTTP Request data chunk not a Buffer");
|
||||||
|
}
|
||||||
msg.payload.push(chunk);
|
msg.payload.push(chunk);
|
||||||
});
|
});
|
||||||
res.on('end',function() {
|
res.on('end',function() {
|
||||||
@ -186,12 +192,12 @@ module.exports = function(RED) {
|
|||||||
node.metric("size.bytes", msg, res.client.bytesRead);
|
node.metric("size.bytes", msg, res.client.bytesRead);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert the payload to the required return type
|
// Convert the payload to the required return type
|
||||||
msg.payload = Buffer.concat(msg.payload); // bin
|
msg.payload = Buffer.concat(msg.payload); // bin
|
||||||
if (node.ret !== "bin") {
|
if (node.ret !== "bin") {
|
||||||
msg.payload = msg.payload.toString('utf8'); // txt
|
msg.payload = msg.payload.toString('utf8'); // txt
|
||||||
|
|
||||||
if (node.ret === "obj") {
|
if (node.ret === "obj") {
|
||||||
try { msg.payload = JSON.parse(msg.payload); } // obj
|
try { msg.payload = JSON.parse(msg.payload); } // obj
|
||||||
catch(e) { node.warn(RED._("httpin.errors.json-error")); }
|
catch(e) { node.warn(RED._("httpin.errors.json-error")); }
|
||||||
@ -234,4 +240,3 @@ module.exports = function(RED) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user