svn commit: r1809196 - /cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/environment/http/HttpEnvironment.java

[email protected] Thu, 21 Sep 2017 18:42:34 -0000
Newsgroups gmane.text.xml.cocoon.cvs
Message-ID <[email protected]>
Author: cdamioli
Date: Thu Sep 21 18:42:34 2017
New Revision: 1809196

URL: http://svn.apache.org/viewvc?rev=1809196&view=rev
Log:
COCOON-2358 Inconsistent Content-Length header for HEAD requests

Modified:
    cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/environment/http/HttpEnvironment.java

Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/environment/http/HttpEnvironment.java
URL: http://svn.apache.org/viewvc/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/environment/http/HttpEnvironment.java?rev=1809196&r1=1809195&r2=1809196&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/environment/http/HttpEnvironment.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/environment/http/HttpEnvironment.java Thu Sep 21 18:42:34 2017
@@ -198,6 +198,19 @@ public class HttpEnvironment extends Abs
     public void setContentLength(int length) {
         this.response.setContentLength(length);
     }
+    
+    public void commitResponse() throws IOException
+    {
+        if (this.secureOutputStream != null) {
+            // COCOOON-2358: for an HEAD request, it is wrong to set the content length to the actual response body size
+            if (this.secureOutputStream.isResettable() && !request.getMethod().equals("HEAD")) {
+                this.setContentLength(this.secureOutputStream.getCount());
+            }
+            this.secureOutputStream.flush();
+        } else if (this.outputStream != null) {
+            this.outputStream.flush();
+        }
+    }
 
     /**
      * Check if the response has been modified since the same