mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
parent
6750be3ec9
commit
f7606e92ca
@ -28,8 +28,43 @@ module.exports = function(RED) {
|
|||||||
var cookie = require("cookie");
|
var cookie = require("cookie");
|
||||||
var hashSum = require("hash-sum");
|
var hashSum = require("hash-sum");
|
||||||
|
|
||||||
|
|
||||||
|
// Cache a reference to the existing https.request function
|
||||||
|
// so we can compare later to see if an old agent-base instance
|
||||||
|
// has been required.
|
||||||
|
// This is generally okay as the core nodes are required before
|
||||||
|
// any contrib nodes. Where it will fail is if the agent-base module
|
||||||
|
// is required via the settings file or outside of Node-RED before it
|
||||||
|
// is started.
|
||||||
|
// If there are other modules that patch the function, they will get undone
|
||||||
|
// as well. Not much we can do about that right now. Patching core
|
||||||
|
// functions is bad.
|
||||||
|
const HTTPS_MODULE = require("https");
|
||||||
|
const HTTPS_REQUEST = HTTPS_MODULE.request;
|
||||||
|
|
||||||
|
function checkNodeAgentPatch() {
|
||||||
|
if (HTTPS_MODULE.request !== HTTPS_REQUEST) {
|
||||||
|
RED.log.warn(`
|
||||||
|
|
||||||
|
---------------------------------------------------------------------
|
||||||
|
Patched https.request function detected. This will break the
|
||||||
|
HTTP Request node. The original code has now been restored.
|
||||||
|
|
||||||
|
This is likely caused by a contrib node including an old version of
|
||||||
|
the 'agent-base@<5.0.0' module.
|
||||||
|
|
||||||
|
You can identify what node is at fault by running:
|
||||||
|
npm list agent-base
|
||||||
|
in your Node-RED user directory (${RED.settings.userDir}).
|
||||||
|
---------------------------------------------------------------------
|
||||||
|
`);
|
||||||
|
HTTPS_MODULE.request = HTTPS_REQUEST
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function HTTPRequest(n) {
|
function HTTPRequest(n) {
|
||||||
RED.nodes.createNode(this,n);
|
RED.nodes.createNode(this,n);
|
||||||
|
checkNodeAgentPatch();
|
||||||
var node = this;
|
var node = this;
|
||||||
var nodeUrl = n.url;
|
var nodeUrl = n.url;
|
||||||
var isTemplatedUrl = (nodeUrl||"").indexOf("{{") != -1;
|
var isTemplatedUrl = (nodeUrl||"").indexOf("{{") != -1;
|
||||||
@ -65,6 +100,7 @@ module.exports = function(RED) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.on("input",function(msg,nodeSend,nodeDone) {
|
this.on("input",function(msg,nodeSend,nodeDone) {
|
||||||
|
checkNodeAgentPatch();
|
||||||
//reset redirectList on each request
|
//reset redirectList on each request
|
||||||
redirectList = [];
|
redirectList = [];
|
||||||
var preRequestTimestamp = process.hrtime();
|
var preRequestTimestamp = process.hrtime();
|
||||||
|
Loading…
Reference in New Issue
Block a user