mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Add cookie handling to HTTP In and HTTP Response nodes
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
module.exports = function(RED) {
|
||||
"use strict";
|
||||
var bodyParser = require("body-parser");
|
||||
var cookieParser = require("cookie-parser");
|
||||
var getBody = require('raw-body');
|
||||
var cors = require('cors');
|
||||
var jsonParser = bodyParser.json();
|
||||
@@ -223,13 +224,13 @@ module.exports = function(RED) {
|
||||
}
|
||||
|
||||
if (this.method == "get") {
|
||||
RED.httpNode.get(this.url,httpMiddleware,corsHandler,metricsHandler,this.callback,this.errorHandler);
|
||||
RED.httpNode.get(this.url,cookieParser(),httpMiddleware,corsHandler,metricsHandler,this.callback,this.errorHandler);
|
||||
} else if (this.method == "post") {
|
||||
RED.httpNode.post(this.url,httpMiddleware,corsHandler,metricsHandler,jsonParser,urlencParser,rawBodyParser,this.callback,this.errorHandler);
|
||||
RED.httpNode.post(this.url,cookieParser(),httpMiddleware,corsHandler,metricsHandler,jsonParser,urlencParser,rawBodyParser,this.callback,this.errorHandler);
|
||||
} else if (this.method == "put") {
|
||||
RED.httpNode.put(this.url,httpMiddleware,corsHandler,metricsHandler,jsonParser,urlencParser,rawBodyParser,this.callback,this.errorHandler);
|
||||
RED.httpNode.put(this.url,cookieParser(),httpMiddleware,corsHandler,metricsHandler,jsonParser,urlencParser,rawBodyParser,this.callback,this.errorHandler);
|
||||
} else if (this.method == "delete") {
|
||||
RED.httpNode.delete(this.url,httpMiddleware,corsHandler,metricsHandler,jsonParser,urlencParser,rawBodyParser,this.callback,this.errorHandler);
|
||||
RED.httpNode.delete(this.url,cookieParser(),httpMiddleware,corsHandler,metricsHandler,jsonParser,urlencParser,rawBodyParser,this.callback,this.errorHandler);
|
||||
}
|
||||
|
||||
this.on("close",function() {
|
||||
@@ -255,6 +256,23 @@ module.exports = function(RED) {
|
||||
if (msg.headers) {
|
||||
msg.res._res.set(msg.headers);
|
||||
}
|
||||
if (msg.cookies) {
|
||||
for (var name in msg.cookies) {
|
||||
if (msg.cookies.hasOwnProperty(name)) {
|
||||
if (msg.cookies[name] === null || msg.cookies[name].value === null) {
|
||||
if (msg.cookies[name]!==null) {
|
||||
msg.res._res.clearCookie('name',msg.cookies[name]);
|
||||
} else {
|
||||
msg.res._res.clearCookie('name');
|
||||
}
|
||||
} else if (typeof msg.cookies[name] === 'object') {
|
||||
msg.res._res.cookie(name,msg.cookies[name].value,msg.cookies[name]);
|
||||
} else {
|
||||
msg.res._res.cookie(name,msg.cookies[name]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
var statusCode = msg.statusCode || 200;
|
||||
if (typeof msg.payload == "object" && !Buffer.isBuffer(msg.payload)) {
|
||||
msg.res._res.status(statusCode).jsonp(msg.payload);
|
||||
|
Reference in New Issue
Block a user