1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

HTTP Request: allow message to override https

Fixes #147
This commit is contained in:
Nick O'Leary 2014-02-06 22:14:27 +00:00
parent 20de0c7c89
commit 7c24c7465a

View File

@ -82,18 +82,19 @@ RED.nodes.registerType("http response",HTTPOut);
function HTTPRequest(n) { function HTTPRequest(n) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
var url = n.url; var nodeUrl = n.url;
var method = n.method || "GET"; var method = n.method || "GET";
var httplib = (/^https/.test(url))?https:http;
var node = this; var node = this;
this.on("input",function(msg) { this.on("input",function(msg) {
var opts = urllib.parse(msg.url||url); var url = msg.url||nodeUrl;
var opts = urllib.parse(url);
opts.method = (msg.method||method).toUpperCase(); opts.method = (msg.method||method).toUpperCase();
if (msg.headers) { if (msg.headers) {
opts.headers = msg.headers; opts.headers = msg.headers;
} }
var req = httplib.request(opts,function(res) { var req = ((/^https/.test(url))?https:http).request(opts,function(res) {
res.setEncoding('utf8'); res.setEncoding('utf8');
msg.statusCode = res.statusCode; msg.statusCode = res.statusCode;
msg.headers = res.headers; msg.headers = res.headers;