2002/05/28 17:50:24
[org.ibex.core.git] / src / org / xwt / HTTP.java
index 52de898..7fa5e3c 100644 (file)
@@ -420,6 +420,24 @@ public class HTTP {
                 while((s = br.readLine()) != null) script += s + "\n";
                 if (Log.on) Log.log(HTTP.ProxyInfo.class, "successfully retrieved WPAD PAC:");
                 if (Log.on) Log.log(HTTP.ProxyInfo.class, script);
+                
+                // MS CARP hack
+                Vector carpHosts = new Vector();
+                for(int i=0; i<script.length(); i++)
+                    if (script.regionMatches(i, "new Node(", 0, 9)) {
+                        String host = script.substring(i + 10, script.indexOf('\"', i + 11));
+                        if (Log.on) Log.log(HTTP.ProxyInfo.class, "Detected MS Proxy Server CARP Script, Host=" + host);
+                        carpHosts.addElement(host);
+                    }
+                if (carpHosts.size() > 0) {
+                    script = "function FindProxyForURL(url, host) {\nreturn \"";
+                    for(int i=0; i<carpHosts.size(); i++)
+                        script += "PROXY " + carpHosts.elementAt(i) + "; ";
+                    script += "\";\n}";
+                    if (Log.on) Log.log(HTTP.ProxyInfo.class, "DeCARPed PAC script:");
+                    if (Log.on) Log.log(HTTP.ProxyInfo.class, script);
+                }
+
                 Script scr = cx.compileReader(proxyAutoConfigRootScope, new StringReader(script), "PAC script at " + url, 0, null);
                 scr.exec(cx, proxyAutoConfigRootScope);
                 return (Function)proxyAutoConfigRootScope.get("FindProxyForURL", null);