How to enable HTTP connection keep-alive or persistent (some call it http reuse)?

I'm designing a front-end on Node-RED dashboard which interfaces with a soap API backend that at first it requires an API login in order perform subsequent API requests. The backed-end expect me to first send the credentials to the url, then it reply with a new URL in the locaiton header (sample response, this new URL I must use in the next API requets.

In order to use the newly provided URL by the response, the first HTTP request should keep the initial HTTP request tcp connection open by using keep-alive property, however this is not happening when sending HTTP request from the "http request" node on Node-RED. I confirmed this using wireshark and compared the capture with another capture doing same API requests with postman.

I also tried to inject the header "connection: keep-alive" in the before the http request node, however Node-Red is overwriting this header value with "connection: close\r\n" specifically. It seems like the HTTP request node is not maintaining persistent connection.

Here is what I'm injecting before the http request node to enfore the connection header:

msg.headers = {
"connection" : "keep-alive",
"my-custom-header": "samplevalue",
"User-Agent": "My User Agent"
return msg;

Actually regardless the connection header is set to keep-alive or close, I always see the FIN flag in the TCP connection initiated by Node-RED (not the server). It seems like Node-RED is not maintaining HTTP connections eventhough the keep-alive header.

Now I start to think that Node-RED http requets node is not allowing http connection reuse (persistant http connection) and I'm wondering whether there is a workaround on Node-RED to allow it or some settings on Node-RED itself to make it capable of maintaining persistent connection?

Appreciate your help

1 Like