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
1 changed files with 5 additions and 4 deletions

View File

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