node-red icon indicating copy to clipboard operation
node-red copied to clipboard

HTTP-In Node, msg.req.headers is a virtual object in Node 16

Open sammachin opened this issue 2 years ago • 0 comments

Current Behavior

In Node 15.1.0 the headers object on an http.IncommingMessage was changed to be lazily computed See https://nodejs.org/dist/latest-v16.x/docs/api/http.html#messageheaders (expand history) This means that if you use a debug node to inspect an incoming request and log the whole msg object or msg.req you will not see the headers object.

However if you log msg.req.headers explicitly it does show, equally you can access this object in other nodes such as a change node.

However this is confusing for a developer trying to debug their flows, especially as the change is effected by the underlying NodeJS version not even the version of Node-RED

Expected Behavior

HTTP In node should always explicitly set the msg.req.headers or the documentation/help text should be amended to clarify this behaviour.

Steps To Reproduce

Use the below flow and observe in the msg.req debug node that the object does not have a headers property but in the other msg.req.headers node there are values.

Example flow

[
    {
        "id": "74cc7a7d7b3c32e1",
        "type": "http in",
        "z": "791c52d6ca37529a",
        "name": "",
        "url": "/test",
        "method": "get",
        "upload": false,
        "swaggerDoc": "",
        "x": 200,
        "y": 620,
        "wires": [
            [
                "d32b952f00451e0c",
                "d8673124ecd1a618",
                "226f21b347d2db4c"
            ]
        ]
    },
    {
        "id": "d32b952f00451e0c",
        "type": "http response",
        "z": "791c52d6ca37529a",
        "name": "",
        "statusCode": "",
        "headers": {},
        "x": 230,
        "y": 720,
        "wires": []
    },
    {
        "id": "226f21b347d2db4c",
        "type": "debug",
        "z": "791c52d6ca37529a",
        "name": "msg.req.headers",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "req.headers",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 530,
        "y": 600,
        "wires": []
    },
    {
        "id": "d8673124ecd1a618",
        "type": "debug",
        "z": "791c52d6ca37529a",
        "name": "msg.req",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "req",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 500,
        "y": 720,
        "wires": []
    }
]

Environment

  • Node-RED version: 3.0.2 & 2.2.3
  • Node.js version: 16.16
  • npm version: 8
  • Platform/OS: Mac
  • Browser: Chrome

sammachin avatar Sep 07 '22 11:09 sammachin