mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Allow http to accept delete properly, and put, options etc.
This commit is contained in:
parent
07fd5a5f5f
commit
cf25b2866e
@ -50,7 +50,7 @@ module.exports = function(RED) {
|
|||||||
|
|
||||||
this.url = n.url;
|
this.url = n.url;
|
||||||
this.method = n.method;
|
this.method = n.method;
|
||||||
this.swaggerDoc = n.swaggerDoc;
|
this.swaggerDoc = n.swaggerDoc;
|
||||||
|
|
||||||
var node = this;
|
var node = this;
|
||||||
|
|
||||||
@ -60,7 +60,7 @@ module.exports = function(RED) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.callback = function(req,res) {
|
this.callback = function(req,res) {
|
||||||
if (node.method == "post") {
|
if (node.method.match(/(^post$|^delete$|^put$|^options$)/)) {
|
||||||
node.send({req:req,res:res,payload:req.body});
|
node.send({req:req,res:res,payload:req.body});
|
||||||
} else if (node.method == "get") {
|
} else if (node.method == "get") {
|
||||||
node.send({req:req,res:res,payload:req.query});
|
node.send({req:req,res:res,payload:req.query});
|
||||||
@ -82,7 +82,7 @@ module.exports = function(RED) {
|
|||||||
metricsHandler = function(req, res, next) {
|
metricsHandler = function(req, res, next) {
|
||||||
var startAt = process.hrtime();
|
var startAt = process.hrtime();
|
||||||
onHeaders(res, function() {
|
onHeaders(res, function() {
|
||||||
if(res._msgId) {
|
if (res._msgId) {
|
||||||
var diff = process.hrtime(startAt);
|
var diff = process.hrtime(startAt);
|
||||||
var ms = diff[0] * 1e3 + diff[1] * 1e-6;
|
var ms = diff[0] * 1e3 + diff[1] * 1e-6;
|
||||||
var metricResponseTime = ms.toFixed(3);
|
var metricResponseTime = ms.toFixed(3);
|
||||||
@ -103,7 +103,7 @@ module.exports = function(RED) {
|
|||||||
} else if (this.method == "put") {
|
} else if (this.method == "put") {
|
||||||
RED.httpNode.put(this.url,corsHandler,metricsHandler,jsonParser,urlencParser,rawBodyParser,this.callback,this.errorHandler);
|
RED.httpNode.put(this.url,corsHandler,metricsHandler,jsonParser,urlencParser,rawBodyParser,this.callback,this.errorHandler);
|
||||||
} else if (this.method == "delete") {
|
} else if (this.method == "delete") {
|
||||||
RED.httpNode.delete(this.url,corsHandler,metricsHandler,this.callback,this.errorHandler);
|
RED.httpNode.delete(this.url,corsHandler,metricsHandler,jsonParser,urlencParser,rawBodyParser,this.callback,this.errorHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.on("close",function() {
|
this.on("close",function() {
|
||||||
@ -259,7 +259,7 @@ module.exports = function(RED) {
|
|||||||
var ms = diff[0] * 1e3 + diff[1] * 1e-6;
|
var ms = diff[0] * 1e3 + diff[1] * 1e-6;
|
||||||
var metricRequestDurationMillis = ms.toFixed(3);
|
var metricRequestDurationMillis = ms.toFixed(3);
|
||||||
node.metric("duration.millis", msg, metricRequestDurationMillis);
|
node.metric("duration.millis", msg, metricRequestDurationMillis);
|
||||||
if(res.client && res.client.bytesRead) {
|
if (res.client && res.client.bytesRead) {
|
||||||
node.metric("size.bytes", msg, res.client.bytesRead);
|
node.metric("size.bytes", msg, res.client.bytesRead);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user