diff --git a/nodes/core/io/21-httpin.html b/nodes/core/io/21-httpin.html index 4802314bc..a4cac1f9f 100644 --- a/nodes/core/io/21-httpin.html +++ b/nodes/core/io/21-httpin.html @@ -79,6 +79,16 @@ +
cookies
, if set, can be used to set or delete cookies.
+ The statusCode
and headers
can also be set within
+ the node itself. If a property is set within the node, it cannot be overridden
+ by the corresponding message property.
The cookies
property must be an object of name/value pairs.
The value can be either a string to set the value of the cookie with default
@@ -120,6 +133,7 @@ msg.cookies = {
diff --git a/nodes/core/io/21-httpin.js b/nodes/core/io/21-httpin.js
index 418dc7444..57c8f734a 100644
--- a/nodes/core/io/21-httpin.js
+++ b/nodes/core/io/21-httpin.js
@@ -268,10 +268,20 @@ module.exports = function(RED) {
function HTTPOut(n) {
RED.nodes.createNode(this,n);
var node = this;
+ this.headers = n.headers||{};
+ this.statusCode = n.statusCode;
this.on("input",function(msg) {
if (msg.res) {
+ var headers = RED.util.cloneMessage(node.headers);
if (msg.headers) {
- msg.res._res.set(msg.headers);
+ for (var h in msg.headers) {
+ if (msg.headers.hasOwnProperty(h) && !headers.hasOwnProperty(h)) {
+ headers[h] = msg.headers[h];
+ }
+ }
+ }
+ if (Object.keys(headers).length > 0) {
+ msg.res._res.set(headers);
}
if (msg.cookies) {
for (var name in msg.cookies) {
@@ -290,7 +300,7 @@ module.exports = function(RED) {
}
}
}
- var statusCode = msg.statusCode || 200;
+ var statusCode = node.statusCode || msg.statusCode || 200;
if (typeof msg.payload == "object" && !Buffer.isBuffer(msg.payload)) {
msg.res._res.status(statusCode).jsonp(msg.payload);
} else {
diff --git a/nodes/core/locales/en-US/messages.json b/nodes/core/locales/en-US/messages.json
index f6cb9113a..7a13c2dd8 100644
--- a/nodes/core/locales/en-US/messages.json
+++ b/nodes/core/locales/en-US/messages.json
@@ -314,7 +314,9 @@
"url": "URL",
"doc": "Docs",
"return": "Return",
- "upload": "Accept file uploads?"
+ "upload": "Accept file uploads?",
+ "status": "Status code",
+ "headers": "Headers"
},
"setby": "- set by msg.method -",
"basicauth": "Use basic authentication",