Anonymous avatar Anonymous committed dede3f9

- CacheFilter does not set encoding properly
- backporting changes from release 2.2
Issue number: CACHE-159
Submitted by: Lars Torunski

Comments (0)

Files changed (3)

src/core/java/com/opensymphony/oscache/web/filter/CacheFilter.java

 public class CacheFilter implements Filter {
     private final Log log = LogFactory.getLog(this.getClass());
 
+    // Header
+    public static final String HEADER_CONTENT_ENCODING = "Content-Encoding";
+    
     // filter variables
     private FilterConfig config;
     private ServletCacheAdministrator admin = null;

src/core/java/com/opensymphony/oscache/web/filter/CacheHttpServletResponseWrapper.java

 
 import java.io.IOException;
 import java.io.PrintWriter;
+import java.io.OutputStreamWriter;
 
 import java.util.Locale;
 
         if (log.isDebugEnabled()) {
             log.debug("header: " + name + ": " + value);
         }
+        
+        if (CacheFilter.HEADER_CONTENT_ENCODING.equalsIgnoreCase(name)) {
+            result.setContentEncoding(value);
+        }
 
         super.setHeader(name, value);
     }
 
     /**
+     * Add a header field
+     *
+     * @param name The header name
+     * @param value The header value
+     */
+    public void addHeader(String name, String value) {
+        if (log.isDebugEnabled()) {
+            log.debug("header: " + name + ": " + value);
+        }
+
+        if (CacheFilter.HEADER_CONTENT_ENCODING.equalsIgnoreCase(name)) {
+            result.setContentEncoding(value);
+        }
+
+        super.addHeader(name, value);
+    }
+
+    
+    /**
      * Set the int value of the header
      *
      * @param name The header name
      */
     public PrintWriter getWriter() throws IOException {
         if (cachedWriter == null) {
-            cachedWriter = new PrintWriter(getOutputStream());
+            cachedWriter = new PrintWriter(new OutputStreamWriter(getOutputStream(), result.getContentEncoding()));
         }
 
         return cachedWriter;

src/core/java/com/opensymphony/oscache/web/filter/ResponseContent.java

     private transient ByteArrayOutputStream bout = new ByteArrayOutputStream(1000);
     private Locale locale = null;
     private String contentType = null;
+    private String contentEncoding = null;
     private byte[] content = null;
     private long lastModified = -1;
 
         contentType = value;
     }
 
+    public String getContentEncoding() {
+        return contentEncoding;
+    }
+
+    public void setContentEncoding(String contentEncoding) {
+        this.contentEncoding = contentEncoding;
+    }
+    
     public long getLastModified() {
         return lastModified;
     }
         out.write(content);
         out.flush();
     }
+
 }
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.