Now sets Vary header. Minor code clean up & fixes.

This commit is contained in:
Harald Kuhr 2012-06-21 10:55:14 +02:00
parent 4db12d313b
commit 75c09d3aef
2 changed files with 20 additions and 23 deletions

View File

@ -122,7 +122,6 @@ public class GZIPFilter extends GenericFilter {
String accept = request.getHeader("Accept-Encoding"); String accept = request.getHeader("Accept-Encoding");
if (accept != null && accept.contains("gzip")) { if (accept != null && accept.contains("gzip")) {
//System.out.println("GZIP supported, compressing."); //System.out.println("GZIP supported, compressing.");
// TODO: Set Vary: Accept-Encoding ?!
GZIPResponseWrapper wrapped = new GZIPResponseWrapper(response); GZIPResponseWrapper wrapped = new GZIPResponseWrapper(response);
try { try {

View File

@ -51,6 +51,8 @@ import java.util.zip.GZIPOutputStream;
* @version $Id: GZIPResponseWrapper.java#1 $ * @version $Id: GZIPResponseWrapper.java#1 $
*/ */
public class GZIPResponseWrapper extends HttpServletResponseWrapper { public class GZIPResponseWrapper extends HttpServletResponseWrapper {
// TODO: Remove/update ETags if needed? Read the spec (RFC 2616) on Vary/ETag for caching
protected ServletOutputStream out; protected ServletOutputStream out;
protected PrintWriter writer; protected PrintWriter writer;
protected GZIPOutputStream gzipOut; protected GZIPOutputStream gzipOut;
@ -58,7 +60,9 @@ public class GZIPResponseWrapper extends HttpServletResponseWrapper {
public GZIPResponseWrapper(final HttpServletResponse response) { public GZIPResponseWrapper(final HttpServletResponse response) {
super(response); super(response);
response.addHeader("Content-Encoding", "gzip"); response.addHeader("Content-Encoding", "gzip");
response.addHeader("Vary", "Accept");
} }
public ServletOutputStream createOutputStream() throws IOException { public ServletOutputStream createOutputStream() throws IOException {
@ -76,8 +80,7 @@ public class GZIPResponseWrapper extends HttpServletResponseWrapper {
} }
// TODO: Move this to flushbuffer or something? Hmmm.. // TODO: Move this to flushbuffer or something? Hmmm..
public void flushResponse() { public void flushResponse() throws IOException {
try {
try { try {
// Finish GZIP encodig // Finish GZIP encodig
if (gzipOut != null) { if (gzipOut != null) {
@ -98,11 +101,6 @@ public class GZIPResponseWrapper extends HttpServletResponseWrapper {
} }
} }
} }
catch (IOException e) {
// TODO: Fix this one...
e.printStackTrace();
}
}
public void flushBuffer() throws IOException { public void flushBuffer() throws IOException {
if (writer != null) { if (writer != null) {