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

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


The following commit(s) were added to refs/heads/main by this push:
     new acf179ba38 Improve handling of Servlet 5.7 response closure
acf179ba38 is described below

commit acf179ba383c672a1d83f004a01fdbd5f276192c
Author: Mark Thomas <[email protected]>
AuthorDate: Tue Sep 29 17:19:45 2026 +0100

    Improve handling of Servlet 5.7 response closure
---
 java/org/apache/catalina/connector/OutputBuffer.java | 12 ++++++++----
 webapps/docs/changelog.xml                           |  6 ++++++
 2 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/java/org/apache/catalina/connector/OutputBuffer.java 
b/java/org/apache/catalina/connector/OutputBuffer.java
index ee1a3a56b6..12d463a941 100644
--- a/java/org/apache/catalina/connector/OutputBuffer.java
+++ b/java/org/apache/catalina/connector/OutputBuffer.java
@@ -440,11 +440,15 @@ public class OutputBuffer extends Writer {
         /*
          * Handle the requirements of section 5.7 of the Servlet specification 
- Closure of the Response Object.
          *
-         * Currently, this just handles the simple case. There is work in 
progress to better define what should happen
-         * if an attempt is made to write > content-length bytes. When that 
work is complete, this is likely where the
-         * implementation will end up.
+         * For the blocking case, the output is closed once content-length 
bytes have been written.
+         *
+         * For the non-blocking case, there may be bytes buffered at the 
SocketWrapper so only close the output if an
+         * attempt is made to write more the content-length bytes.
+         *
+         * There is work in progress to better define what should happen if an 
attempt is made to write > content-length
+         * bytes. When that work is complete, this is likely where the 
implementation will end up.
          */
-        if (contentLength != -1 && bytesWritten >= contentLength) {
+        if (contentLength != -1 && (bytesWritten == contentLength && 
isBlocking() || bytesWritten > contentLength)) {
             close();
         }
     }
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 7f82af3f43..8395a38545 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -339,6 +339,12 @@
         Fix a timing issue that could cause large non-blocking writes to stall
         for AJP connections. (markt)
       </fix>
+      <fix>
+        Improve the handling of the requirements for response closure in 
section
+        5.7 of the Servlet specification. If a non-blocking write writes 
exactly
+        content-length bytes to the response, allow that write to complete in a
+        non-blocking manner before the response is closed. (markt)
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Jasper">


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to