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

change http request to use http_proxy environment rather than do it ourselves

This commit is contained in:
dceejay 2015-05-19 09:45:00 +01:00
parent e852d1e57c
commit 38ab1550d2
3 changed files with 35 additions and 29 deletions

View File

@ -152,7 +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>
<p><b>Note</b>: If you need to configure a proxy please add <b>http_proxy=...</b> to your environment variables and restart Node-RED.</p>
</script>
<script type="text/javascript">

View File

@ -248,19 +248,25 @@ module.exports = function(RED) {
}
}
if (opts.headers['content-length'] == null) {
if (Buffer.isBuffer(payload)) {
opts.headers['content-length'] = payload.length;
} else {
opts.headers['content-length'] = Buffer.byteLength(payload);
}
}
}
var urltotest = url;
if (RED.settings.httpNodeProxy) {
var proxy = RED.settings.httpNodeProxy.host;
if (process.env.http_proxy != null) {
var match = process.env.http_proxy.match(/^(http:\/\/)?([^:\/]+)(:([0-9]+))?/i);
if (match) {
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.host = opts.hostname = match[2],
opts.port = (match[4] != null ? match[4] : 80),
opts.path = opts.pathname = opts.href;
urltotest = proxy;
urltotest = match[2];
}
else { node.warn("Bad proxy url: "+process.env.http_proxy); }
}
var req = ((/^https/.test(urltotest))?https:http).request(opts,function(res) {
(node.ret === "bin") ? res.setEncoding('binary') : res.setEncoding('utf8');

View File

@ -18,7 +18,6 @@
// to make it available:
//var fs = require("fs");
module.exports = {
// the tcp port that the Node-RED web server is listening on
uiPort: 1880,
@ -121,9 +120,11 @@ 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 },
// If you need to set an http proxy please set an environment variable
// called http_proxy outside of Node-RED in the operating system.
// For example - http_proxy=http://myproxy.com:8080
// (Setting it here will have no effect)
// The following property can be used to add a custom middleware function
// in front of all http in nodes. This allows custom authentication to be
@ -148,7 +149,6 @@ module.exports = {
// j5board:require("johnny-five").Board({repl:false})
},
// The following property can be used to order the categories in the editor
// palette. If a node's category is not in the list, the category will get
// added to the end of the palette.