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>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> <li><code>headers</code> is an object containing the response headers</li>
</ul> </ul>
<p><b>Note</b>: See the <i>settings.js</i> file if you need to configure a proxy.</p>
</script> </script>
<script type="text/javascript"> <script type="text/javascript">

View File

@ -243,7 +243,18 @@ module.exports = function(RED) {
opts.headers['content-length'] = Buffer.byteLength(payload); 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'); (node.ret === "bin") ? res.setEncoding('binary') : res.setEncoding('utf8');
msg.statusCode = res.statusCode; msg.statusCode = res.statusCode;
msg.headers = res.headers; msg.headers = res.headers;

View File

@ -121,6 +121,10 @@ module.exports = {
// methods: "GET,PUT,POST,DELETE" // 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. // Anything in this hash is globally available to all functions.
// It is accessed as context.global. // It is accessed as context.global.
// eg: // eg: