Browse files

A fix for Cappuccino issue 759.

amendment.
  • Loading branch information...
1 parent 153c465 commit 7e201097b9c85e9084261bf187871a312dc50a64 @danielphelps danielphelps committed with paulbaumgart Feb 28, 2011
Showing with 21 additions and 2 deletions.
  1. +9 −1 engines/rhino/bin/narwhal-rhino
  2. +12 −1 engines/rhino/lib/http-client-engine.js
View
10 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
View
13 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);

0 comments on commit 7e20109

Please sign in to comment.