mirror of
https://github.com/haraldk/TwelveMonkeys.git
synced 2025-08-02 11:05:29 -04:00
Now sets Vary header. Minor code clean up & fixes.
This commit is contained in:
parent
4db12d313b
commit
75c09d3aef
@ -122,7 +122,6 @@ public class GZIPFilter extends GenericFilter {
|
||||
String accept = request.getHeader("Accept-Encoding");
|
||||
if (accept != null && accept.contains("gzip")) {
|
||||
//System.out.println("GZIP supported, compressing.");
|
||||
// TODO: Set Vary: Accept-Encoding ?!
|
||||
GZIPResponseWrapper wrapped = new GZIPResponseWrapper(response);
|
||||
|
||||
try {
|
||||
|
@ -51,6 +51,8 @@ import java.util.zip.GZIPOutputStream;
|
||||
* @version $Id: GZIPResponseWrapper.java#1 $
|
||||
*/
|
||||
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 PrintWriter writer;
|
||||
protected GZIPOutputStream gzipOut;
|
||||
@ -58,7 +60,9 @@ public class GZIPResponseWrapper extends HttpServletResponseWrapper {
|
||||
|
||||
public GZIPResponseWrapper(final HttpServletResponse response) {
|
||||
super(response);
|
||||
|
||||
response.addHeader("Content-Encoding", "gzip");
|
||||
response.addHeader("Vary", "Accept");
|
||||
}
|
||||
|
||||
public ServletOutputStream createOutputStream() throws IOException {
|
||||
@ -76,31 +80,25 @@ public class GZIPResponseWrapper extends HttpServletResponseWrapper {
|
||||
}
|
||||
|
||||
// TODO: Move this to flushbuffer or something? Hmmm..
|
||||
public void flushResponse() {
|
||||
public void flushResponse() throws IOException {
|
||||
try {
|
||||
try {
|
||||
// Finish GZIP encodig
|
||||
if (gzipOut != null) {
|
||||
gzipOut.finish();
|
||||
}
|
||||
// Finish GZIP encodig
|
||||
if (gzipOut != null) {
|
||||
gzipOut.finish();
|
||||
}
|
||||
|
||||
flushBuffer();
|
||||
}
|
||||
finally {
|
||||
// Close stream
|
||||
if (writer != null) {
|
||||
writer.close();
|
||||
}
|
||||
else {
|
||||
if (out != null) {
|
||||
out.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
flushBuffer();
|
||||
}
|
||||
catch (IOException e) {
|
||||
// TODO: Fix this one...
|
||||
e.printStackTrace();
|
||||
finally {
|
||||
// Close stream
|
||||
if (writer != null) {
|
||||
writer.close();
|
||||
}
|
||||
else {
|
||||
if (out != null) {
|
||||
out.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user