mirror of
				https://github.com/node-red/node-red.git
				synced 2025-03-01 10:36:34 +00:00 
			
		
		
		
	Fix connection keep-alive in http request node
This commit is contained in:
		| @@ -23,6 +23,8 @@ module.exports = async function(RED) { | ||||
|     const { v4: uuid } = require('uuid'); | ||||
|     const crypto = require('crypto'); | ||||
|     const URL = require("url").URL | ||||
|     const http = require("http") | ||||
|     const https = require("https") | ||||
|     var mustache = require("mustache"); | ||||
|     var querystring = require("querystring"); | ||||
|     var cookie = require("cookie"); | ||||
| @@ -65,16 +67,27 @@ in your Node-RED user directory (${RED.settings.userDir}). | ||||
|     function HTTPRequest(n) { | ||||
|         RED.nodes.createNode(this,n); | ||||
|         checkNodeAgentPatch(); | ||||
|         var node = this; | ||||
|         var nodeUrl = n.url; | ||||
|         var isTemplatedUrl = (nodeUrl||"").indexOf("{{") != -1; | ||||
|         var nodeMethod = n.method || "GET"; | ||||
|         var paytoqs = false; | ||||
|         var paytobody = false; | ||||
|         var redirectList = []; | ||||
|         var sendErrorsToCatch = n.senderr; | ||||
|         const node = this; | ||||
|         const nodeUrl = n.url; | ||||
|         const isTemplatedUrl = (nodeUrl||"").indexOf("{{") != -1; | ||||
|         const nodeMethod = n.method || "GET"; | ||||
|         let paytoqs = false; | ||||
|         let paytobody = false; | ||||
|         let redirectList = []; | ||||
|         const sendErrorsToCatch = n.senderr; | ||||
|         node.headers = n.headers || []; | ||||
|         var nodeHTTPPersistent = n["persist"]; | ||||
|         const useKeepAlive = n["persist"]; | ||||
|         let agents = null | ||||
|         if (useKeepAlive) { | ||||
|             agents = { | ||||
|                 http: new http.Agent({ keepAlive: true }), | ||||
|                 https: new https.Agent({ keepAlive: true }) | ||||
|             } | ||||
|             node.on('close', function () { | ||||
|                 agents.http.destroy() | ||||
|                 agents.https.destroy() | ||||
|             }) | ||||
|         } | ||||
|         if (n.tls) { | ||||
|             var tlsNode = RED.nodes.getNode(n.tls); | ||||
|         } | ||||
| @@ -560,12 +573,14 @@ in your Node-RED user directory (${RED.settings.userDir}). | ||||
|                     opts.agent = { | ||||
|                         http: new HttpProxyAgent(proxyOptions), | ||||
|                         https: new HttpsProxyAgent(proxyOptions) | ||||
|                     }; | ||||
|  | ||||
|                     } | ||||
|                 } else { | ||||
|                     node.warn("Bad proxy url: "+ prox); | ||||
|                 } | ||||
|             } | ||||
|             if (useKeepAlive && !opts.agent) { | ||||
|                 opts.agent = agents | ||||
|             } | ||||
|             if (tlsNode) { | ||||
|                 opts.https = {}; | ||||
|                 tlsNode.addTLSOptions(opts.https); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user