2003/09/28 21:54:51
authormegacz <megacz@xwt.org>
Fri, 30 Jan 2004 07:38:39 +0000 (07:38 +0000)
committermegacz <megacz@xwt.org>
Fri, 30 Jan 2004 07:38:39 +0000 (07:38 +0000)
darcs-hash:20040130073839-2ba56-69861dc32e470a09d2a3e8a4cf3dfa0a92bc130a.gz

src/org/xwt/HTTP.java

index 8f26528..38488e0 100644 (file)
@@ -54,9 +54,6 @@ public class HTTP {
     /** cache for resolveAndCheckIfFirewalled() */
     static Hashtable resolvedHosts = new Hashtable();
 
-    /** if any request encounters an IOException, the entire HTTP connection is invalidated */
-    boolean invalid = false;
-
     /** true iff we are allowed to skip the resolve check (only allowed when we're downloading the PAC script) */
     boolean skipResolveCheck = false;
 
@@ -88,12 +85,12 @@ public class HTTP {
         Semaphore blockOn = null;
         Semaphore releaseMe = null;
         synchronized(this) {
-            if (invalid) throw new HTTPException("connection failed on a previous pipelined call");
             try {
                 connect();
                 sendRequest(contentType, content);
             } catch (IOException e) {
-                invalid = true;
+                sock = null;
+                in = null;
                 throw e;
             }
             blockOn = okToRecieve;
@@ -104,7 +101,12 @@ public class HTTP {
         boolean doRelease = true;
         try {
             if (blockOn != null) blockOn.block();
-            if (invalid) throw new HTTPException("connection failed on a previous pipelined call");
+            
+            // previous call wrecked the socket connection, but we already sent our request, so we can't just retry --
+            // this could cause the server to receive the request twice, which could be bad (think of the case where the
+            // server call causes Amazon.com to ship you an item with one-click purchasing).
+            if (sock == null)
+                throw new HTTPException("a previous pipelined call messed up the socket");
             
             Hashtable h = in == null ? null : parseHeaders(in);
             if (h == null) {
@@ -145,7 +147,7 @@ public class HTTP {
                 
             }
             
-        } catch (IOException e) { invalid = true; throw e;
+        } catch (IOException e) { sock = null; in = null; throw e;
         } finally { if (doRelease) releaseMe.release();
         }
     }
@@ -543,7 +545,7 @@ public class HTTP {
                 }
                 return ret;
             } finally {
-                if (!good) invalid = true;
+                if (!good) { this.HTTP.sock = null; this.HTTP.in = null; }
             }
         }