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/25 13:57:12 UTC
[tomcat] 02/03: Revert "Don't set 'C-L: 0' for HEAD requests if Servlet doesn't specify C-L"
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 b38281c8263d1a978594dd4e950f382bc7d96dba
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Thu May 25 14:15:09 2023 +0100
Revert "Don't set 'C-L: 0' for HEAD requests if Servlet doesn't specify C-L"
This reverts commit 7d9cacdfc2e073ef4b1493d14f5c8f9f47a00c7f.
This broke too many things. It was also not quite right but even the correct
fix broke quite a few tests.
The fundamental problem is that Tomcat can't differentiate between a HEAD request
that opts not to write any data to save resources (and should not have any C-L
header) and a HEAD request explicitly writes zero byres because that is what the
corresponding GET would do (which should have a header of C-L: 0).
Rather than risk regressions, leave the current behaviour as-is.
---
java/org/apache/catalina/connector/OutputBuffer.java | 6 +++---
webapps/docs/changelog.xml | 5 -----
2 files changed, 3 insertions(+), 8 deletions(-)
diff --git a/java/org/apache/catalina/connector/OutputBuffer.java b/java/org/apache/catalina/connector/OutputBuffer.java
index 0e5bd6659e..62966c653b 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 &&
- !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.getContentLengthLong() == -1)) {
+ // 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 d7cc56b496..d1fe84b1d2 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -124,11 +124,6 @@
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