From af899b9fc37691e066a58abe5e923b148d010258 Mon Sep 17 00:00:00 2001 From: Steve-Mcl Date: Thu, 10 Mar 2022 07:58:38 +0000 Subject: [PATCH] TRACE should return orig msg in body... - https://httpwg.org/specs/rfc7231.html#rfc.section.4.3.8 --- .../@node-red/nodes/core/network/21-httpin.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/packages/node_modules/@node-red/nodes/core/network/21-httpin.js b/packages/node_modules/@node-red/nodes/core/network/21-httpin.js index b782bb42a..1034012ec 100644 --- a/packages/node_modules/@node-red/nodes/core/network/21-httpin.js +++ b/packages/node_modules/@node-red/nodes/core/network/21-httpin.js @@ -205,18 +205,24 @@ module.exports = function(RED) { res.sendStatus(500); }; - this.callback = function(req,res) { - var msgid = RED.util.generateId(); + this.callback = function (req, res, next) { + const msgid = RED.util.generateId(); + const resWrap = createResponseWrapper(node, res); res._msgid = msgid; if (node.method.match(/^(post|delete|put|options|patch)$/)) { - node.send({_msgid:msgid,req:req,res:createResponseWrapper(node,res),payload:req.body}); + node.send({ _msgid: msgid, req: req, res: resWrap, payload: req.body }); } else if (node.method == "get") { - node.send({_msgid:msgid,req:req,res:createResponseWrapper(node,res),payload:req.query}); + node.send({ _msgid: msgid, req: req, res: resWrap, payload: req.query }); } else if (node.method == "trace") { + // https://httpwg.org/specs/rfc7231.html#rfc.section.4.3.8 res.set('Content-Type', 'message/http') - node.send({_msgid:msgid,req:req,res:createResponseWrapper(node,res)}); + // Add REQ string to body (e.g. TRACE / HTTP/1.1) + let pl = `TRACE ${req.path} ${req.protocol.toUpperCase()}/${req.httpVersion}\n`; + // Add REQ headers to body + pl += Object.entries(req.headers).map(e => e.join(": ")).join("\n"); + node.send({ _msgid: msgid, req: req, res: resWrap, payload: pl }); } else { - node.send({_msgid:msgid,req:req,res:createResponseWrapper(node,res)}); + node.send({ _msgid: msgid, req: req, res: resWrap }); } };