2002/07/01 22:02:10
[org.ibex.core.git] / src / org / xwt / HTTP.java
index 7fa5e3c..6323b52 100644 (file)
@@ -64,8 +64,8 @@ public class HTTP {
         if (port == -1) port = ssl ? 443 : 80;
         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
+        addHeader("Host", host);                                           // host header is always sent verbatim
+        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);
@@ -74,7 +74,6 @@ public class HTTP {
         if (sock == null && pi != null && pi.socksProxyHost != null) sock = attemptSocksProxy(pi.socksProxyHost, pi.socksProxyPort);
         if (sock == null) sock = attemptDirect();
         if (sock == null) throw new HTTPException("all socket creation attempts have failed");
-        sock.setTcpNoDelay(true);
     }
 
 
@@ -84,13 +83,13 @@ 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);
 
@@ -102,7 +101,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
@@ -112,7 +111,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);
         }
@@ -287,7 +286,6 @@ public class HTTP {
         } else {
             PrintWriter pw = new PrintWriter(new OutputStreamWriter(sock.getOutputStream()));
             pw.print("GET " + path + " HTTP/1.0\r\n");
-            System.out.println("GET " + path + " HTTP/1.0\r\n");
             pw.print("User-Agent: XWT\r\n");
             pw.print(headers);
             pw.print("\r\n");
@@ -297,7 +295,7 @@ public class HTTP {
         in = new BufferedInputStream(sock.getInputStream());
 
         // we can't use a BufferedReader directly on the input stream,
-        // since it will buffer beyond the end of the headers
+        // since it will buffer past the end of the headers
         byte[] buf = new byte[4096];
         int buflen = 0;
         while(true) {
@@ -364,7 +362,11 @@ public class HTTP {
         /** the PAC script */
         public Function proxyAutoConfigFunction = null;
 
+        // 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"); }
@@ -392,6 +394,7 @@ public class HTTP {
                 if (Log.on) Log.log(Platform.class, "xwt-proxy-* detection failed due to: " + e);
                 return null;
             }
+            */
         }
 
         // FIXME: search up from default domain