# How to handle http requests which not ends (with (-out bearer) token)

**URL:** <https://discourse.nodered.org/t/how-to-handle-http-requests-which-not-ends-with-out-bearer-token/101526>\
**Category:** General\
**Created:** [24 July 2026 16:59 UTC](https://discourse.nodered.org/t/how-to-handle-http-requests-which-not-ends-with-out-bearer-token/101526 "2026-07-24T16:59:51Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![CosmicDuck](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cosmicduck/32/108061_2.png) [@CosmicDuck](https://discourse.nodered.org/u/CosmicDuck)\
**Post date:** [24 July 2026 16:59 UTC](https://discourse.nodered.org/t/how-to-handle-http-requests-which-not-ends-with-out-bearer-token/101526/1 "2026-07-24T16:59:51Z")

</div>

Hello,

i have a device which streams the status line by line (at connection and if changed) but does not end the connection.  
I tried the http-request node and the www-request node but both will get only timeouts without send the already gotten message.  
Here a example of the never ending connection with curl:

```auto
user@host:~$ ${CURL_EXE} -X GET http://${ANTHOST}/api/v1/miner/status -H "Authorization: ${TOKEN}" -H "Content-Type: application/json"
{"status":3}
{"status":2}
{"status":3}

```

I must kill the curl to get it back.  
Normally I want only the first line and then the connection could be closed. But also a never closed connection is ok as long each json line will result in a messag on the output node.

I tried it by injecting the complete parameters to the input node. With other api targets which will closed after response I have no problem.

How can I handle such a connection and which module can I use?  
The authentification is also a little bit tricky because the token will expire after some time so a hard stored value is not possible (it's not a Bearing token because Bearing word is not allowed, check the curl line for details).

Any idea?

---

<div class="post-metadata">

**Author:** ![CosmicDuck](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cosmicduck/32/108061_2.png) [@CosmicDuck](https://discourse.nodered.org/u/CosmicDuck)\
**Post date:** [24 July 2026 17:36 UTC](https://discourse.nodered.org/t/how-to-handle-http-requests-which-not-ends-with-out-bearer-token/101526/2 "2026-07-24T17:36:16Z")

</div>

Gemini was helping me after I ask to use the tcp request node. It has a limit feature which I used ( 2000 ms) and I added simply a function node with a simple line by line exception json parser code. The preparation for the input was a little bit more complex. That works for me.

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [24 July 2026 17:51 UTC](https://discourse.nodered.org/t/how-to-handle-http-requests-which-not-ends-with-out-bearer-token/101526/3 "2026-07-24T17:51:36Z")

</div>

I'm glad you found a solution.

You didn't give much in the way of details but it does sound like something that should be possible with the standard nodes and without writing a custom json parser.

---

<div class="post-metadata">

**Author:** ![CosmicDuck](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cosmicduck/32/108061_2.png) [@CosmicDuck](https://discourse.nodered.org/u/CosmicDuck)\
**Post date:** [24 July 2026 19:33 UTC](https://discourse.nodered.org/t/how-to-handle-http-requests-which-not-ends-with-out-bearer-token/101526/4 "2026-07-24T19:33:06Z")

</div>

Oh it's really simple in this way so you will not get an warning or error:

I get this answer from the tcp node:  
`{"payload":"HTTP/1.1 200 OK\r\nconnection: close\r\ntransfer-encoding: chunked\r\ndate: Fri, 24 Jul 2026 17:28:33 GMT\r\n\r\nD\r\n{\"status\":3}\n\r\n","_msgid":"0eddd21306c59baf","url":"http://192.168.16.165/api/v1/auth/login","method":"POST","statusCode":200,"headers":{"content-type":"application/json","content-length":"45","date":"Fri, 24 Jul 2026 17:28:32 GMT","x-node-red-request-node":"e67885d2"},"responseUrl":"http://192.168.16.165/api/v1/auth/login","redirectList":[],"retry":0,"host":"192.168.16.165","port":80}`

Simply split is by lines with a loop line by line put each to the json parser.  
Catch the expeption to do nothing.  
If a json is found make whatever you want with it like store them in the msg.payload

```auto
let rawData = msg.payload;

if (rawData && typeof rawData === 'string') {
    // In einzelne Zeilen zerlegen
    let lines = rawData.split('\n');

    for (let line of lines) {
        line = line.trim();
        if (!line) continue;

        // Versuchen, jede Zeile direkt als JSON zu parsen
        try {
            let data = JSON.parse(line);

            // Prüfen, ob das geparste JSON unsere "status"-Eigenschaft enthält
            if (data && data.status !== undefined) {
                let statusVal = data.status;

                // Status im Context speichern
                flow.set('miner_status_code', statusVal);
                
                let statusText = (statusVal === 2 ? "normal" : (statusVal === 3 ? "paused" : `status_${statusVal}`));
                flow.set('miner_api_status', statusText);

                // Visuelles Feedback am Node
                let timeStr = new Date().toLocaleTimeString();
                node.status({
                    fill: (statusVal === 2 ? "green" : "yellow"),
                    shape: "dot",
                    text: `Status: ${statusVal} (${statusText}) [${timeStr}]`
                });

                // Geparstes JSON als Payload ausgeben
                msg.payload = data;
                return msg;
            }
        } catch (e) {
            // Header, Chunk-Größen (wie "D") etc. schlagen fehl und werden einfach übersprungen
        }
    }
}

return null;

```

---

<div class="post-metadata">

**Author:** ![CosmicDuck](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cosmicduck/32/108061_2.png) [@CosmicDuck](https://discourse.nodered.org/u/CosmicDuck)\
**Post date:** [24 July 2026 19:36 UTC](https://discourse.nodered.org/t/how-to-handle-http-requests-which-not-ends-with-out-bearer-token/101526/5 "2026-07-24T19:36:55Z")

</div>

Here the preparation code for the tcp node:

```auto
let minerIp = flow.get('miner_ip');
let token = flow.get('miner_token');

if (!token) {
    node.error("Kein miner_token im Flow-Kontext vorhanden!");
    return null;
}

// HTTP/1.1 Request Header manuell zusammensetzen
// Wichtig: \r\n als Zeilenumbruch und \r\n\r\n am Ende des Headers!
let rawHttpRequest = 
    `GET /api/v1/miner/status HTTP/1.1\r\n` +
    `Host: ${minerIp}\r\n` +
    `User-Agent: Node-RED\r\n` +
    `Authorization: ${token}\r\n` +
    `Content-Type: application/json\r\n` +
    `Connection: close\r\n` +
    `\r\n`;

msg.host = minerIp;
msg.port = 80;
msg.payload = rawHttpRequest;

return msg;

```

The tcp node is configured:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/b/7b65169c05285b6906beaca2b0dd85a99179b582.png)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [7 August 2026 19:37 UTC](https://discourse.nodered.org/t/how-to-handle-http-requests-which-not-ends-with-out-bearer-token/101526/6 "2026-08-07T19:37:54Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
