mirror of https://github.com/node-red/node-red.git
Merge f6959d1c18
into 686efc4720
commit
3a1ba56f54
|
@ -23,6 +23,9 @@
|
|||
<option value="put">PUT</option>
|
||||
<option value="delete">DELETE</option>
|
||||
<option value="patch">PATCH</option>
|
||||
<option value="head">HEAD</option>
|
||||
<option value="options">OPTIONS</option>
|
||||
<option value="trace">TRACE</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-row form-row-http-in-upload hide">
|
||||
|
|
|
@ -171,9 +171,18 @@ module.exports = function(RED) {
|
|||
|
||||
if (RED.settings.httpNodeCors) {
|
||||
corsHandler = cors(RED.settings.httpNodeCors);
|
||||
RED.httpNode.options("*",corsHandler);
|
||||
}
|
||||
|
||||
RED.httpNode.options("*", function(req,res,next) {
|
||||
//see if any routes for this path exist & call next() otherwise call corsHandler
|
||||
const routes = RED.httpNode._router.stack.filter(e => e.route && e.route.path == req.path && e.route.methods.options === true);
|
||||
if(routes.length > 0) {
|
||||
next();
|
||||
return
|
||||
}
|
||||
corsHandler(req,res,next);
|
||||
});
|
||||
|
||||
function HTTPIn(n) {
|
||||
RED.nodes.createNode(this,n);
|
||||
if (RED.settings.httpNodeRoot !== false) {
|
||||
|
@ -197,8 +206,9 @@ 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;
|
||||
// Since Node 15, req.headers are lazily computed and the property
|
||||
// marked as non-enumerable.
|
||||
|
@ -210,11 +220,19 @@ module.exports = function(RED) {
|
|||
enumerable: true
|
||||
})
|
||||
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')
|
||||
// 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 });
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -262,6 +280,8 @@ module.exports = function(RED) {
|
|||
|
||||
if (this.method == "get") {
|
||||
RED.httpNode.get(this.url,cookieParser(),httpMiddleware,corsHandler,metricsHandler,this.callback,this.errorHandler);
|
||||
} else if (this.method == "head") { // https://httpwg.org/specs/rfc7231.html#rfc.section.4.3.2
|
||||
RED.httpNode.head(this.url,cookieParser(),httpMiddleware,corsHandler,metricsHandler,this.callback,this.errorHandler);
|
||||
} else if (this.method == "post") {
|
||||
RED.httpNode.post(this.url,cookieParser(),httpMiddleware,corsHandler,metricsHandler,jsonParser,urlencParser,multipartParser,rawBodyParser,this.callback,this.errorHandler);
|
||||
} else if (this.method == "put") {
|
||||
|
@ -270,6 +290,10 @@ module.exports = function(RED) {
|
|||
RED.httpNode.patch(this.url,cookieParser(),httpMiddleware,corsHandler,metricsHandler,jsonParser,urlencParser,rawBodyParser,this.callback,this.errorHandler);
|
||||
} else if (this.method == "delete") {
|
||||
RED.httpNode.delete(this.url,cookieParser(),httpMiddleware,corsHandler,metricsHandler,jsonParser,urlencParser,rawBodyParser,this.callback,this.errorHandler);
|
||||
} else if (this.method == "options") { // https://httpwg.org/specs/rfc7231.html#rfc.section.4.3.7
|
||||
RED.httpNode.options(this.url,cookieParser(),httpMiddleware,metricsHandler,jsonParser,urlencParser,rawBodyParser,this.callback,this.errorHandler);
|
||||
} else if (this.method == "trace") { // https://httpwg.org/specs/rfc7231.html#rfc.section.4.3.8
|
||||
RED.httpNode.trace(this.url,cookieParser(),httpMiddleware,corsHandler,metricsHandler,this.callback,this.errorHandler);
|
||||
}
|
||||
|
||||
this.on("close",function() {
|
||||
|
|
|
@ -19,8 +19,18 @@
|
|||
<h3>Outputs</h3>
|
||||
<dl class="message-properties">
|
||||
<dt>payload</dt>
|
||||
<dd>For a GET request, contains an object of any query string parameters.
|
||||
Otherwise, contains the body of the HTTP request.</dd>
|
||||
<dd>
|
||||
<ul>
|
||||
<li><code>GET</code> - <code>payload</code> contains an object of any query string parameters passed in the HTTP Request </li>
|
||||
<li><code>POST</code> - <code>payload</code> contains the body of the HTTP Request </li>
|
||||
<li><code>PUT</code> - <code>payload</code> contains the body of the HTTP Request </li>
|
||||
<li><code>DELETE</code> - <code>payload</code> contains the body of the HTTP Request </li>
|
||||
<li><code>PATCH</code> - <code>payload</code> contains the body of the HTTP Request </li>
|
||||
<li><code>HEAD</code> - <code>payload</code> the HEAD method has no payload </li>
|
||||
<li><code>OPTIONS</code> - <code>payload</code> contains the body of the HTTP Request </li>
|
||||
<li><code>TRACE</code> - <code>payload</code> contains the details of the HTTP Request in the body </li>
|
||||
</ul>
|
||||
</dd>
|
||||
<dt>req<span class="property-type">object</span></dt>
|
||||
<dd>An HTTP request object. This object contains multiple properties that
|
||||
provide information about the request.
|
||||
|
|
Loading…
Reference in New Issue