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

Adds proxy support to http node - via settings.js

This commit is contained in:
dceejay 2015-05-13 13:54:47 +01:00
parent 0bef04ae0a
commit 17f3366556
3 changed files with 22 additions and 6 deletions

View File

@ -152,6 +152,7 @@
<li><code>statusCode</code> is the status code of the response, or the error code if the request could not be completed</li>
<li><code>headers</code> is an object containing the response headers</li>
</ul>
<p><b>Note</b>: See the <i>settings.js</i> file if you need to configure a proxy.</p>
</script>
<script type="text/javascript">
@ -199,9 +200,9 @@
$("#node-input-path").html(root);
$("#node-input-tip").show();
}
if(!RED.nodes.getType("swagger-doc")){
$('.row-swagger-doc').hide();
}
if(!RED.nodes.getType("swagger-doc")){
$('.row-swagger-doc').hide();
}
}
});

View File

@ -192,7 +192,7 @@ module.exports = function(RED) {
return;
}
// url must start http:// or https:// so assume http:// if not set
if (!((url.indexOf("http://")===0) || (url.indexOf("https://")===0))) {
if (!((url.indexOf("http://") === 0) || (url.indexOf("https://") === 0))) {
url = "http://"+url;
}
@ -243,7 +243,18 @@ module.exports = function(RED) {
opts.headers['content-length'] = Buffer.byteLength(payload);
}
}
var req = ((/^https/.test(url))?https:http).request(opts,function(res) {
var urltotest = url;
if (RED.settings.httpNodeProxy) {
var proxy = RED.settings.httpNodeProxy.host;
opts.protocol = "http:";
opts.headers['Host'] = opts.host;
opts.host = opts.hostname = proxy;
opts.port = RED.settings.httpNodeProxy.port || opts.port;
if (opts.port) { opts.host = opts.host+":"+opts.port; }
opts.path = opts.pathname = opts.href;
urltotest = proxy;
}
var req = ((/^https/.test(urltotest))?https:http).request(opts,function(res) {
(node.ret === "bin") ? res.setEncoding('binary') : res.setEncoding('utf8');
msg.statusCode = res.statusCode;
msg.headers = res.headers;

View File

@ -121,6 +121,10 @@ module.exports = {
// methods: "GET,PUT,POST,DELETE"
//},
// The following property can be used to configure a proxy for use by the
// http request node.
//httpNodeProxy : { host:"myproxy.acme.com", port:8080 },
// Anything in this hash is globally available to all functions.
// It is accessed as context.global.
// eg: