1
0
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:
dceejay 2015-05-07 16:45:44 +01:00
parent 07fd5a5f5f
commit cf25b2866e

View File

@ -50,7 +50,7 @@ module.exports = function(RED) {
this.url = n.url;
this.method = n.method;
this.swaggerDoc = n.swaggerDoc;
this.swaggerDoc = n.swaggerDoc;
var node = this;
@ -60,7 +60,7 @@ module.exports = function(RED) {
};
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});
} else if (node.method == "get") {
node.send({req:req,res:res,payload:req.query});
@ -82,7 +82,7 @@ module.exports = function(RED) {
metricsHandler = function(req, res, next) {
var startAt = process.hrtime();
onHeaders(res, function() {
if(res._msgId) {
if (res._msgId) {
var diff = process.hrtime(startAt);
var ms = diff[0] * 1e3 + diff[1] * 1e-6;
var metricResponseTime = ms.toFixed(3);
@ -103,7 +103,7 @@ module.exports = function(RED) {
} else if (this.method == "put") {
RED.httpNode.put(this.url,corsHandler,metricsHandler,jsonParser,urlencParser,rawBodyParser,this.callback,this.errorHandler);
} 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() {
@ -259,7 +259,7 @@ module.exports = function(RED) {
var ms = diff[0] * 1e3 + diff[1] * 1e-6;
var metricRequestDurationMillis = ms.toFixed(3);
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);
}
}