From 1708f424a0b52d407f3efdcce84cf8895d60a664 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Damioli?= Date: Thu, 21 Sep 2017 18:42:34 +0000 Subject: [PATCH] COCOON-2358 Inconsistent Content-Length header for HEAD requests git-svn-id: https://svn.apache.org/repos/asf/cocoon/branches/BRANCH_2_1_X@1809196 13f79535-47bb-0310-9956-ffa450edef68 --- .../cocoon/environment/http/HttpEnvironment.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/java/org/apache/cocoon/environment/http/HttpEnvironment.java b/src/java/org/apache/cocoon/environment/http/HttpEnvironment.java index 52b48d269b1..948bd28f372 100644 --- a/src/java/org/apache/cocoon/environment/http/HttpEnvironment.java +++ b/src/java/org/apache/cocoon/environment/http/HttpEnvironment.java @@ -198,6 +198,19 @@ public String getContentType() { 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