mirror of
https://github.com/haraldk/TwelveMonkeys.git
synced 2025-08-02 19:15: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");
|
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 {
|
||||||
|
@ -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,31 +80,25 @@ 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) {
|
gzipOut.finish();
|
||||||
gzipOut.finish();
|
}
|
||||||
}
|
|
||||||
|
|
||||||
flushBuffer();
|
flushBuffer();
|
||||||
}
|
|
||||||
finally {
|
|
||||||
// Close stream
|
|
||||||
if (writer != null) {
|
|
||||||
writer.close();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (out != null) {
|
|
||||||
out.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (IOException e) {
|
finally {
|
||||||
// TODO: Fix this one...
|
// Close stream
|
||||||
e.printStackTrace();
|
if (writer != null) {
|
||||||
|
writer.close();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (out != null) {
|
||||||
|
out.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user