tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From violet...@apache.org
Subject svn commit: r1803616 - in /tomcat/trunk: java/org/apache/coyote/http11/Http11Processor.java test/org/apache/coyote/http11/TestHttp11Processor.java webapps/docs/changelog.xml
Date Tue, 01 Aug 2017 07:08:37 GMT
Author: violetagg
Date: Tue Aug  1 07:08:36 2017
New Revision: 1803616

URL: http://svn.apache.org/viewvc?rev=1803616&view=rev
Log:
Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=61086
Ensure to explicitly signal an empty request body for HTTP 205 responses.
Additional fix to r1795278. Based on a patch provided by Alexandr Saperov.

Modified:
    tomcat/trunk/java/org/apache/coyote/http11/Http11Processor.java
    tomcat/trunk/test/org/apache/coyote/http11/TestHttp11Processor.java
    tomcat/trunk/webapps/docs/changelog.xml

Modified: tomcat/trunk/java/org/apache/coyote/http11/Http11Processor.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/Http11Processor.java?rev=1803616&r1=1803615&r2=1803616&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/Http11Processor.java (original)
+++ tomcat/trunk/java/org/apache/coyote/http11/Http11Processor.java Tue Aug  1 07:08:36 2017
@@ -851,6 +851,8 @@ public class Http11Processor extends Abs
                 // RFC 7231 requires the server to explicitly signal an empty
                 // response in this case
                 response.setContentLength(0);
+            } else {
+                response.setContentLength(-1);
             }
         }
 
@@ -882,9 +884,6 @@ public class Http11Processor extends Abs
         }
 
         MimeHeaders headers = response.getMimeHeaders();
-        if (!entityBody) {
-            response.setContentLength(-1);
-        }
         // A SC_NO_CONTENT response may include entity headers
         if (entityBody || statusCode == HttpServletResponse.SC_NO_CONTENT) {
             String contentType = response.getContentType();

Modified: tomcat/trunk/test/org/apache/coyote/http11/TestHttp11Processor.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/coyote/http11/TestHttp11Processor.java?rev=1803616&r1=1803615&r2=1803616&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/coyote/http11/TestHttp11Processor.java (original)
+++ tomcat/trunk/test/org/apache/coyote/http11/TestHttp11Processor.java Tue Aug  1 07:08:36
2017
@@ -47,6 +47,7 @@ import javax.servlet.http.HttpServletRes
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
 import org.junit.Assert;
@@ -972,4 +973,38 @@ public class TestHttp11Processor extends
             }
         }
     }
+
+    @Test
+    public void testBug61086() throws Exception {
+        Tomcat tomcat = getTomcatInstance();
+
+        // No file system docBase required
+        Context ctx = tomcat.addContext("", null);
+
+        Bug61086Servlet servlet = new Bug61086Servlet();
+        Tomcat.addServlet(ctx, "Test", servlet);
+        ctx.addServletMappingDecoded("/test", "Test");
+
+        tomcat.start();
+
+        ByteChunk responseBody = new ByteChunk();
+        Map<String,List<String>> responseHeaders = new HashMap<>();
+        int rc = getUrl("http://localhost:" + getPort() + "/test", responseBody, responseHeaders);
+
+        assertEquals(HttpServletResponse.SC_RESET_CONTENT, rc);
+        assertNotNull(responseHeaders.get("Content-Length"));
+        assertTrue("0".equals(responseHeaders.get("Content-Length").get(0)));
+        assertTrue(responseBody.getLength() == 0);
+    }
+
+    private static final class Bug61086Servlet extends HttpServlet {
+
+        private static final long serialVersionUID = 1L;
+
+        @Override
+        protected void doGet(HttpServletRequest req, HttpServletResponse resp)
+                throws ServletException, IOException {
+            resp.setStatus(205);
+        }
+    }
 }

Modified: tomcat/trunk/webapps/docs/changelog.xml
URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1803616&r1=1803615&r2=1803616&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/trunk/webapps/docs/changelog.xml Tue Aug  1 07:08:36 2017
@@ -70,6 +70,11 @@
   </subsection>
   <subsection name="Coyote">
     <changelog>
+      <fix>
+        <bug>61086</bug>: Ensure to explicitly signal an empty request body for
+        HTTP 205 responses. Additional fix to r1795278. Based on a patch
+        provided by Alexandr Saperov. (violetagg)
+      </fix>
       <update>
         <bug>61345</bug>: Add a server listener that can be used to do system
         property replacement from the property source configured in the



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


Mime
View raw message