commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r230882 - in /jakarta/commons/proper/httpclient/trunk/src: java/org/apache/commons/httpclient/HttpMethodBase.java test/org/apache/commons/httpclient/TestResponseHeaders.java
Date Mon, 08 Aug 2005 20:40:17 GMT
Author: olegk
Date: Mon Aug  8 13:40:11 2005
New Revision: 230882

URL: http://svn.apache.org/viewcvs?rev=230882&view=rev
Log:
PR #35085 (An HTTP "204 NO CONTENT" response results in dropped connection)

Contributed by Ian Bray <Ian.Bray at logicacmg.com>
Reviewed by Oleg Kalnichevski & Michael Becke

Modified:
    jakarta/commons/proper/httpclient/trunk/src/java/org/apache/commons/httpclient/HttpMethodBase.java
    jakarta/commons/proper/httpclient/trunk/src/test/org/apache/commons/httpclient/TestResponseHeaders.java

Modified: jakarta/commons/proper/httpclient/trunk/src/java/org/apache/commons/httpclient/HttpMethodBase.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/httpclient/trunk/src/java/org/apache/commons/httpclient/HttpMethodBase.java?rev=230882&r1=230881&r2=230882&view=diff
==============================================================================
--- jakarta/commons/proper/httpclient/trunk/src/java/org/apache/commons/httpclient/HttpMethodBase.java
(original)
+++ jakarta/commons/proper/httpclient/trunk/src/java/org/apache/commons/httpclient/HttpMethodBase.java
Mon Aug  8 13:40:11 2005
@@ -1673,6 +1673,7 @@
         if (Wire.CONTENT_WIRE.enabled()) {
             is = new WireLogInputStream(is, Wire.CONTENT_WIRE);
         }
+        boolean canHaveBody = canResponseHaveBody(statusLine.getStatusCode());
         InputStream result = null;
         Header transferEncodingHeader = responseHeaders.getFirstHeader("Transfer-Encoding");
         // We use Transfer-Encoding if present and ignore Content-Length.
@@ -1711,15 +1712,16 @@
         } else {
             long expectedLength = getResponseContentLength();
             if (expectedLength == -1) {
-                Header connectionHeader = responseHeaders.getFirstHeader("Connection");
-                String connectionDirective = null;
-                if (connectionHeader != null) {
-                    connectionDirective = connectionHeader.getValue();
-                }
-                if (this.effectiveVersion.greaterEquals(HttpVersion.HTTP_1_1) &&

-                    !"close".equalsIgnoreCase(connectionDirective)) {
-                    LOG.info("Response content length is not known");
-                    setConnectionCloseForced(true);
+                if (canHaveBody && this.effectiveVersion.greaterEquals(HttpVersion.HTTP_1_1))
{
+                    Header connectionHeader = responseHeaders.getFirstHeader("Connection");
+                    String connectionDirective = null;
+                    if (connectionHeader != null) {
+                        connectionDirective = connectionHeader.getValue();
+                    }
+                    if (!"close".equalsIgnoreCase(connectionDirective)) {
+                        LOG.info("Response content length is not known");
+                        setConnectionCloseForced(true);
+                    }
                 }
                 result = is;            
             } else {
@@ -1728,7 +1730,7 @@
         } 
 
         // See if the response is supposed to have a response body
-        if (!canResponseHaveBody(statusLine.getStatusCode())) {
+        if (!canHaveBody) {
             result = null;
         }
         // if there is a result - ALWAYS wrap it in an observer which will

Modified: jakarta/commons/proper/httpclient/trunk/src/test/org/apache/commons/httpclient/TestResponseHeaders.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/httpclient/trunk/src/test/org/apache/commons/httpclient/TestResponseHeaders.java?rev=230882&r1=230881&r2=230882&view=diff
==============================================================================
--- jakarta/commons/proper/httpclient/trunk/src/test/org/apache/commons/httpclient/TestResponseHeaders.java
(original)
+++ jakarta/commons/proper/httpclient/trunk/src/test/org/apache/commons/httpclient/TestResponseHeaders.java
Mon Aug  8 13:40:11 2005
@@ -363,4 +363,45 @@
                 method.shouldCloseConnection(connectionManager.getConection()));
 		assertFalse("Connection should NOT be closed", method.isConnectionCloseForced());
 	}
+    
+    public void testNoContent() throws Exception {
+        // test with connection header
+        this.server.setRequestHandler(new HttpRequestHandler() {
+            public boolean processRequest(SimpleHttpServerConnection conn,
+                    SimpleRequest request) throws IOException {
+                ResponseWriter out = conn.getWriter();
+                out.println("HTTP/1.1 204 NO CONTENT");
+                out.println();
+                out.flush();
+                return true;
+            }
+        });
+
+        GetMethod method = new GetMethod("/");
+        client.executeMethod(method);
+        method.getResponseBodyAsString();
+
+        assertTrue(connectionManager.getConection().isOpen());
+
+        // test without connection header
+        this.server.setRequestHandler(new HttpRequestHandler() {
+            public boolean processRequest(SimpleHttpServerConnection conn,
+                    SimpleRequest request) throws IOException {
+                ResponseWriter out = conn.getWriter();
+                out.println("HTTP/1.1 204 NO CONTENT");
+                out.println("Connection: keep-alive");
+                out.println();
+                out.flush();
+                return true;
+            }
+        });
+
+        // test with connection header
+        method = new GetMethod("/");
+        client.executeMethod(method);
+        method.getResponseBodyAsString();
+
+        assertTrue(connectionManager.getConection().isOpen());
+    }
+    
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message