I just committed the fix for PR 28580 to classpath.

The problem was that in cases where there is no response body, a persistent connection would never be returned to the connection pool. Also if you tried to read a body from a HEAD request where the server indicated chucked-encoding, the read would hang (instead of immediately returning EOF).

Earlier today I committed a mauve testcase for this problem.

Do we want to bring this into libgcj before this would be imported also?


2006-08-11  David Daney  <[EMAIL PROTECTED]>

        PR classpath/28580
        * gnu/java/net/protocol/http/Request.java (readResponse):  Call
        createResponseBodyStream in more cases and with new parameter.
(createResponseBodyStream): Added new parameter mayHaveBody. Handle
        HEAD and !mayHaveBody responses specially.
Index: gnu/java/net/protocol/http/Request.java
===================================================================
RCS file: /sources/classpath/classpath/gnu/java/net/protocol/http/Request.java,v
retrieving revision 1.9
diff -u -p -r1.9 Request.java
--- gnu/java/net/protocol/http/Request.java	3 Mar 2006 23:05:33 -0000	1.9
+++ gnu/java/net/protocol/http/Request.java	11 Aug 2006 20:41:44 -0000
@@ -419,13 +419,16 @@ public class Request
     switch (code)
       {
       case 100:
+        break;
       case 204:
       case 205:
       case 304:
+        body = createResponseBodyStream(responseHeaders, majorVersion,
+                                        minorVersion, in, false);
         break;
       default:
         body = createResponseBodyStream(responseHeaders, majorVersion,
-                                        minorVersion, in);
+                                        minorVersion, in, true);
       }
 
     // Construct response
@@ -453,7 +456,8 @@ public class Request
   private InputStream createResponseBodyStream(Headers responseHeaders,
                                                int majorVersion,
                                                int minorVersion,
-                                               InputStream in)
+                                               InputStream in,
+                                               boolean mayHaveBody)
     throws IOException
   {
     long contentLength = -1;
@@ -466,7 +470,12 @@ public class Request
       (majorVersion == 1 && minorVersion == 0);
 
     String transferCoding = responseHeaders.getValue("Transfer-Encoding");
-    if ("chunked".equalsIgnoreCase(transferCoding))
+    if ("HEAD".equals(method) || !mayHaveBody)
+      {
+        // Special case no body.
+        in = new LimitedLengthInputStream(in, 0, true, connection, doClose);
+      }
+    else if ("chunked".equalsIgnoreCase(transferCoding))
       {
         in = new LimitedLengthInputStream(in, -1, false, connection, doClose);
           

Reply via email to