X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fxwt%2FHTTP.java;h=64cfdbab971ad9a4b3225fc50f96b0232a62d6f0;hb=55854fa1b8f8f33fb064674b43761a0515c10960;hp=702e9930dcec328a744512b5089fec65cbd4b35c;hpb=3f00891d4c3f98028ec8dfd23fd6009de2c41893;p=org.ibex.core.git diff --git a/src/org/xwt/HTTP.java b/src/org/xwt/HTTP.java index 702e993..64cfdba 100644 --- a/src/org/xwt/HTTP.java +++ b/src/org/xwt/HTTP.java @@ -65,7 +65,7 @@ public class HTTP { host = this.url.getHost(); if (Log.on) Log.log(this, "creating HTTP object for connection to " + host + ":" + port); addHeader("Host", host); // host header is always sent verbatim - if (!skipResolveCheck) host = resolveAndCheckIfFirewalled(host); // might have to use the strict IP if behind a proxy + if (!skipResolveCheck) resolveAndCheckIfFirewalled(host); // might have to use the strict IP if behind a proxy ProxyInfo pi = Platform.detectProxy(); if (sock == null && pi != null && pi.proxyAutoConfigFunction != null) sock = attemptPAC(pi.proxyAutoConfigFunction); @@ -83,16 +83,19 @@ public class HTTP { * resolves the hostname and returns it as a string in the form "x.y.z.w", except for the special case "xmlrpc.xwt.org". * @throws HTTPException if the host falls within a firewalled netblock */ - private String resolveAndCheckIfFirewalled(String host) throws HTTPException { + private void resolveAndCheckIfFirewalled(String host) throws HTTPException { // special case - if (host.equals("xmlrpc.xwt.org")) return host; + if (host.equals("xmlrpc.xwt.org")) return; // cached - if (resolvedHosts.get(host) != null) return (String)resolvedHosts.get(host); + if (resolvedHosts.get(host) != null) return; if (Log.on) Log.log(this, " resolveAndCheckIfFirewalled: resolving " + host); + // if all scripts are trustworthy (local FS), continue + if (Main.originAddr == null) return; + // resolve using DNS try { InetAddress addr = InetAddress.getByName(host); @@ -101,7 +104,7 @@ public class HTTP { (quadbyte[0] == 192 && quadbyte[1] == 168) || (quadbyte[0] == 172 && (quadbyte[1] & 0xF0) == 16)) && !addr.equals(Main.originAddr)) throw new HTTPException("security violation: " + host + " [" + addr.getHostAddress() + "] is in a firewalled netblock"); - return addr.getHostAddress(); + return; } catch (UnknownHostException uhe) { } // resolve using xmlrpc.xwt.org @@ -111,7 +114,7 @@ public class HTTP { Object ret = new XMLRPC("http://xmlrpc.xwt.org/RPC2/", "dns.resolve").call(new Object[] { host }); if (ret == null || !(ret instanceof String)) throw new Exception(" xmlrpc.xwt.org returned non-String: " + ret); resolvedHosts.put(host, ret); - return (String)ret; + return; } catch (Throwable e) { throw new HTTPException("exception while attempting to use xmlrpc.xwt.org to resolve " + host + ": " + e); } @@ -140,10 +143,10 @@ public class HTTP { if (!ssl) { path = "http://" + host + ":" + port + path; } else { - if (Log.on) Log.log(this, "attempting to create HTTP proxied socket using proxy " + proxyHost + ":" + proxyPort); PrintWriter pw = new PrintWriter(new OutputStreamWriter(sock.getOutputStream())); BufferedReader br = new BufferedReader(new InputStreamReader(sock.getInputStream())); - pw.print("CONNECT " + host + ":" + port + " HTTP/1.0\r\n\r\n"); + pw.print("CONNECT " + host + ":" + port + " HTTP/1.1\r\n\r\n"); + pw.flush(); String s = br.readLine(); if (s.charAt(9) != '2') throw new HTTPException("proxy refused CONNECT method: \"" + s + "\""); while (br.readLine().length() > 0) { }; @@ -365,36 +368,53 @@ public class HTTP { // this method has been disabled because it was causing problems -- some domains are set up so that *.foo.com resolves // to a single IP, for any value of *. If the client's home domain is foo.com, then xwt-proxy-httpHost will resolve erroneously. public static ProxyInfo detectProxyViaManual() { - return null; - /* - try { - // continue iff one of the two resolves - try { InetAddress.getByName("xwt-proxy-httpHost"); } - catch (UnknownHostException e) { InetAddress.getByName("xwt-proxy-socksHost"); } - - if (Log.on) Log.log(Platform.class, "using xwt-proxy-* configuration"); - ProxyInfo ret = new ProxyInfo(); - try { - ret.httpProxyHost = InetAddress.getByName("xwt-proxy-httpHost").getHostAddress(); - byte[] quadbyte = InetAddress.getByName("xwt-proxy-httpPort").getAddress(); - ret.httpProxyPort = ((quadbyte[1] & 0xff) * 10000) + ((quadbyte[2] & 0xff) * 100) + (quadbyte[3] & 0xff); - } catch (UnknownHostException e) { } - try { - ret.httpsProxyHost = InetAddress.getByName("xwt-proxy-httpsHost").getHostAddress(); - byte[] quadbyte = InetAddress.getByName("xwt-proxy-httpsPort").getAddress(); - ret.httpsProxyPort = ((quadbyte[1] & 0xff) * 10000) + ((quadbyte[2] & 0xff) * 100) + (quadbyte[3] & 0xff); - } catch (UnknownHostException e) { } - try { - ret.socksProxyHost = InetAddress.getByName("xwt-proxy-socksHost").getHostAddress(); - byte[] quadbyte = InetAddress.getByName("xwt-proxy-socksPort").getAddress(); - ret.socksProxyPort = ((quadbyte[1] & 0xff) * 10000) + ((quadbyte[2] & 0xff) * 100) + (quadbyte[3] & 0xff); - } catch (UnknownHostException e) { } - return ret; - } catch (UnknownHostException e) { - if (Log.on) Log.log(Platform.class, "xwt-proxy-* detection failed due to: " + e); - return null; + ProxyInfo ret = new ProxyInfo(); + + ret.httpProxyHost = Platform.getEnv("http_proxy"); + if (ret.httpProxyHost != null) { + if (ret.httpProxyHost.startsWith("http://")) ret.httpProxyHost = ret.httpProxyHost.substring(7); + if (ret.httpProxyHost.endsWith("/")) ret.httpProxyHost = ret.httpProxyHost.substring(0, ret.httpProxyHost.length() - 1); + if (ret.httpProxyHost.indexOf(':') != -1) { + ret.httpProxyPort = Integer.parseInt(ret.httpProxyHost.substring(ret.httpProxyHost.indexOf(':') + 1)); + ret.httpProxyHost = ret.httpProxyHost.substring(0, ret.httpProxyHost.indexOf(':')); + } else { + ret.httpProxyPort = 80; + } + } + + ret.httpsProxyHost = Platform.getEnv("https_proxy"); + if (ret.httpsProxyHost != null) { + if (ret.httpsProxyHost.startsWith("https://")) ret.httpsProxyHost = ret.httpsProxyHost.substring(7); + if (ret.httpsProxyHost.endsWith("/")) ret.httpsProxyHost = ret.httpsProxyHost.substring(0, ret.httpsProxyHost.length() - 1); + if (ret.httpsProxyHost.indexOf(':') != -1) { + ret.httpsProxyPort = Integer.parseInt(ret.httpsProxyHost.substring(ret.httpsProxyHost.indexOf(':') + 1)); + ret.httpsProxyHost = ret.httpsProxyHost.substring(0, ret.httpsProxyHost.indexOf(':')); + } else { + ret.httpsProxyPort = 80; + } + } + + ret.socksProxyHost = Platform.getEnv("socks_proxy"); + if (ret.socksProxyHost != null) { + if (ret.socksProxyHost.startsWith("socks://")) ret.socksProxyHost = ret.socksProxyHost.substring(7); + if (ret.socksProxyHost.endsWith("/")) ret.socksProxyHost = ret.socksProxyHost.substring(0, ret.socksProxyHost.length() - 1); + if (ret.socksProxyHost.indexOf(':') != -1) { + ret.socksProxyPort = Integer.parseInt(ret.socksProxyHost.substring(ret.socksProxyHost.indexOf(':') + 1)); + ret.socksProxyHost = ret.socksProxyHost.substring(0, ret.socksProxyHost.indexOf(':')); + } else { + ret.socksProxyPort = 80; + } + } + + String noproxy = Platform.getEnv("no_proxy"); + if (noproxy != null) { + StringTokenizer st = new StringTokenizer(noproxy, ","); + ret.excluded = new String[st.countTokens()]; + for(int i=0; st.hasMoreTokens(); i++) ret.excluded[i] = st.nextToken(); } - */ + + if (ret.httpProxyHost == null && ret.socksProxyHost == null) return null; + return ret; } // FIXME: search up from default domain @@ -421,15 +441,15 @@ public class HTTP { String s = null; String script = ""; 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); + if (Log.on) Log.log(ProxyInfo.class, "successfully retrieved WPAD PAC:"); + if (Log.on) Log.log(ProxyInfo.class, script); // MS CARP hack Vector carpHosts = new Vector(); for(int i=0; i= d1 && day <= d2) || + (d1 > d2 && (day >= d1 || day <= d2))) ? + Boolean.TRUE : Boolean.FALSE; } };