You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2023/05/24 18:39:27 UTC

[tomcat] branch 10.1.x updated (a810f2c54a -> 7828614e36)

This is an automated email from the ASF dual-hosted git repository.

markt pushed a change to branch 10.1.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git


    from a810f2c54a Reduce code duplication
     new 7d9cacdfc2 Don't set 'C-L: 0' for HEAD requests if Servlet doesn't specify C-L
     new 7828614e36 Fix failing test. There should be no C-L for HEAD unless Servlet sets it

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 java/org/apache/catalina/connector/OutputBuffer.java      | 6 +++---
 test/org/apache/catalina/servlets/TestDefaultServlet.java | 3 ++-
 webapps/docs/changelog.xml                                | 5 +++++
 3 files changed, 10 insertions(+), 4 deletions(-)


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


[tomcat] 01/02: Don't set 'C-L: 0' for HEAD requests if Servlet doesn't specify C-L

Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch 10.1.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git

commit 7d9cacdfc2e073ef4b1493d14f5c8f9f47a00c7f
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Wed May 24 19:38:36 2023 +0100

    Don't set 'C-L: 0' for HEAD requests if Servlet doesn't specify C-L
---
 java/org/apache/catalina/connector/OutputBuffer.java | 6 +++---
 webapps/docs/changelog.xml                           | 5 +++++
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/java/org/apache/catalina/connector/OutputBuffer.java b/java/org/apache/catalina/connector/OutputBuffer.java
index 62966c653b..0e5bd6659e 100644
--- a/java/org/apache/catalina/connector/OutputBuffer.java
+++ b/java/org/apache/catalina/connector/OutputBuffer.java
@@ -232,9 +232,9 @@ public class OutputBuffer extends Writer {
             flushCharBuffer();
         }
 
-        if ((!coyoteResponse.isCommitted()) && (coyoteResponse.getContentLengthLong() == -1)) {
-            // If this didn't cause a commit of the response, the final content
-            // length can be calculated.
+        if (!coyoteResponse.isCommitted() && coyoteResponse.getContentLengthLong() == -1 &&
+                !coyoteResponse.getRequest().method().equals("HEAD")) {
+            // If this didn't cause a commit of the response, the final content length can be calculated.
             if (!coyoteResponse.isCommitted()) {
                 coyoteResponse.setContentLength(bb.remaining());
             }
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index d1fe84b1d2..d7cc56b496 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -124,6 +124,11 @@
         file names in directory listings when using XML output. Based on pull
         request <pr>621</pr> by Alex Kachanov. (markt)
       </fix>
+      <fix>
+        When processing a HEAD request, do not set an HTTP response header for
+        Content-Length with the value zero if the Servlet does not set the
+        header. (markt)
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Coyote">


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


[tomcat] 02/02: Fix failing test. There should be no C-L for HEAD unless Servlet sets it

Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch 10.1.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git

commit 7828614e36069ef1d08ad7eab36b4708bfaae9a2
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Wed May 24 19:39:17 2023 +0100

    Fix failing test. There should be no C-L for HEAD unless Servlet sets it
---
 test/org/apache/catalina/servlets/TestDefaultServlet.java | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/test/org/apache/catalina/servlets/TestDefaultServlet.java b/test/org/apache/catalina/servlets/TestDefaultServlet.java
index b67cc325d4..dca67ff9cb 100644
--- a/test/org/apache/catalina/servlets/TestDefaultServlet.java
+++ b/test/org/apache/catalina/servlets/TestDefaultServlet.java
@@ -636,10 +636,11 @@ public class TestDefaultServlet extends TomcatBaseTest {
         String length = resHeaders.get("Content-Length").get(0);
         Assert.assertEquals(Long.parseLong(length), out.getLength());
         out.recycle();
+        resHeaders.clear();
 
         rc = headUrl(path, out, resHeaders);
         Assert.assertEquals(HttpServletResponse.SC_OK, rc);
         Assert.assertEquals(0, out.getLength());
-        Assert.assertEquals(length, resHeaders.get("Content-Length").get(0));
+        Assert.assertNull(resHeaders.get("Content-Length"));
     }
 }


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