From 7e201097b9c85e9084261bf187871a312dc50a64 Mon Sep 17 00:00:00 2001 From: Daniel Phelps Date: Mon, 28 Feb 2011 15:01:41 -0500 Subject: [PATCH] A fix for Cappuccino issue 759. amendment. --- engines/rhino/bin/narwhal-rhino | 10 +++++++++- engines/rhino/lib/http-client-engine.js | 13 ++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/engines/rhino/bin/narwhal-rhino b/engines/rhino/bin/narwhal-rhino index 40b09d87..ac97f675 100755 --- a/engines/rhino/bin/narwhal-rhino +++ b/engines/rhino/bin/narwhal-rhino @@ -21,7 +21,15 @@ fi CLASSPATH=$NARWHAL_ENGINE_HOME/jars/jna.jar BOOTCLASSPATH=$NARWHAL_ENGINE_HOME/jars/js.jar -JAVA_OPTS="" + +# Parse the http_proxy environment variable. +# http://cache.myproxy.com:42/ => cache.myproxy.com +http_proxy_host=`echo $http_proxy | sed 's/http:\/\/\(.*\):.*/\1/'` + +# http://cache.myproxy.com:42/ => 42 +http_proxy_port=`echo $http_proxy | sed 's/http:\/\/.*:\(.*\)\//\1/'` + +JAVA_OPTS="-Dhttp.proxyHost=$http_proxy_host -Dhttp.proxyPort=$http_proxy_port" if [ -n "$NARWHAL_CLASSPATH" ]; then CLASSPATH=$NARWHAL_CLASSPATH:$CLASSPATH diff --git a/engines/rhino/lib/http-client-engine.js b/engines/rhino/lib/http-client-engine.js index e336556e..164e52e8 100644 --- a/engines/rhino/lib/http-client-engine.js +++ b/engines/rhino/lib/http-client-engine.js @@ -9,8 +9,19 @@ var IO = require("io").IO; exports.open = function(url, mode, options) { var connection, output, input; + function findProxy() { + selector = java.net.ProxySelector.getDefault(); + proxies = selector.select(java.net.URI(url)); + + //This list is never empty -- at the very least, it contains + //java.net.Proxy.NO_PROXY. See java.net.ProxySelector.select() + //and java.net.Proxy. + return proxies.get(0); + } + function initConnection() { - connection = new java.net.URL(url).openConnection(); + proxy = findProxy(); + connection = new java.net.URL(url).openConnection(proxy); connection.setDoInput(true); connection.setDoOutput(false); connection.setRequestMethod(options.method);