You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by hl...@apache.org on 2010/08/31 20:21:23 UTC

svn commit: r991280 - in /tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal: gzip/GZIPEnabledResponse.java services/assets/StackAssetRequestHandler.java

Author: hlship
Date: Tue Aug 31 18:21:22 2010
New Revision: 991280

URL: http://svn.apache.org/viewvc?rev=991280&view=rev
Log:
TAP5-1241: Setting the content length of the response should automatically disable response compression

Modified:
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/gzip/GZIPEnabledResponse.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/StackAssetRequestHandler.java

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/gzip/GZIPEnabledResponse.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/gzip/GZIPEnabledResponse.java?rev=991280&r1=991279&r2=991280&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/gzip/GZIPEnabledResponse.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/gzip/GZIPEnabledResponse.java Tue Aug 31 18:21:22 2010
@@ -1,10 +1,10 @@
-// Copyright 2009 The Apache Software Foundation
+// Copyright 2009, 2010 The Apache Software Foundation
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
 // You may obtain a copy of the License at
 //
-//     http://www.apache.org/licenses/LICENSE-2.0
+// http://www.apache.org/licenses/LICENSE-2.0
 //
 // Unless required by applicable law or agreed to in writing, software
 // distributed under the License is distributed on an "AS IS" BASIS,
@@ -33,8 +33,10 @@ public class GZIPEnabledResponse extends
 
     private final ResponseCompressionAnalyzer analyzer;
 
+    private boolean contentLengthSet = false;
+
     public GZIPEnabledResponse(HttpServletResponse response, HttpServletRequest request, int cutover,
-                               ResponseCompressionAnalyzer analyzer)
+            ResponseCompressionAnalyzer analyzer)
     {
         super(response);
 
@@ -44,14 +46,26 @@ public class GZIPEnabledResponse extends
         this.analyzer = analyzer;
     }
 
+    public void setContentLength(int len)
+    {
+        super.setContentLength(len);
+
+        contentLengthSet = true;
+    }
+
     @Override
     public ServletOutputStream getOutputStream() throws IOException
     {
-        if (request.getAttribute(InternalConstants.SUPPRESS_COMPRESSION) != null)
+        if (contentLengthSet || isCompressionDisabled())
             return super.getOutputStream();
 
         String contentType = getContentType();
 
         return new BufferedGZipOutputStream(contentType, response, cutover, analyzer);
     }
+
+    private boolean isCompressionDisabled()
+    {
+        return request.getAttribute(InternalConstants.SUPPRESS_COMPRESSION) != null;
+    }
 }

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/StackAssetRequestHandler.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/StackAssetRequestHandler.java?rev=991280&r1=991279&r2=991280&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/StackAssetRequestHandler.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/StackAssetRequestHandler.java Tue Aug 31 18:21:22 2010
@@ -92,8 +92,6 @@ public class StackAssetRequestHandler im
         if (productionMode)
             response.setDateHeader("Expires", lastModified + InternalConstants.TEN_YEARS);
 
-        response.disableCompression();
-
         response.setContentLength(cachedStream.size());
 
         if (compress)