Ausgabe des Contents bei 304 unterdrückt
authorKai Moritz <kai@coolibri.de>
Thu, 31 May 2012 21:19:08 +0000 (23:19 +0200)
committerKai Moritz <kai@coolibri.de>
Thu, 2 Aug 2012 07:03:26 +0000 (09:03 +0200)
cachecontrol-example-jsp/src/main/webapp/page-with-forward.jsp
cachecontrol-example-jsp/src/main/webapp/page-with-include.jsp
cachecontrol-example-jsp/src/main/webapp/simple-page.jsp
cachecontrol/src/main/java/de/halbekunst/juplo/cachecontrol/AcceleratorFilter.java

index 786deda..35e4905 100644 (file)
@@ -1,4 +1,4 @@
-<%@page contentType="text/html" pageEncoding="UTF-8" session="false"%>
+<%@page contentType="text/html" pageEncoding="UTF-8" session="false" buffer="1kb" %>
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 
 <html>
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 
 <html>
index 5c3af3e..3347af7 100644 (file)
@@ -1,4 +1,4 @@
-<%@page contentType="text/html" pageEncoding="UTF-8" session="false"%>
+<%@page contentType="text/html" pageEncoding="UTF-8" session="false" buffer="1kb" %>
 <%@taglib uri="/WEB-INF/c.tld" prefix="c"%>
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 
 <%@taglib uri="/WEB-INF/c.tld" prefix="c"%>
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 
index 9010d20..23e5779 100644 (file)
@@ -1,4 +1,4 @@
-<%@page contentType="text/html" pageEncoding="UTF-8" session="false"%>
+<%@page contentType="text/html" pageEncoding="UTF-8" session="false" buffer="1kb" %>
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 
 <html>
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 
 <html>
index 63edfb5..f17ec8d 100644 (file)
@@ -67,8 +67,13 @@ public class AcceleratorFilter implements Filter {
     AccelerationWrapper wrapper = new AccelerationWrapper(httpRequest, httpResponse);
     httpRequest.setAttribute(RESPONSE_WRAPPER, wrapper);
     cacheControl.init(wrapper);
     AccelerationWrapper wrapper = new AccelerationWrapper(httpRequest, httpResponse);
     httpRequest.setAttribute(RESPONSE_WRAPPER, wrapper);
     cacheControl.init(wrapper);
-    chain.doFilter(request, wrapper);
-    wrapper.finish();
+    try {
+      chain.doFilter(request, wrapper);
+      wrapper.finish();
+    }
+    catch (NotModifiedException nm) {
+      log.trace("Not modified: {}", httpRequest.getRequestURI());
+    }
   }
 
   @Override
   }
 
   @Override
@@ -644,8 +649,14 @@ public class AcceleratorFilter implements Filter {
           out().write(buffer);
           committed = true;
           /** Dekoration nur beim ersten Schreib-Schub anstoßen */
           out().write(buffer);
           committed = true;
           /** Dekoration nur beim ersten Schreib-Schub anstoßen */
-          if (pos == size)
-            cacheControl.decorate(request, response);
+          if (pos == size) {
+            if (!cacheControl.decorate(request, response)) {
+              zipped = false;
+              os = null;
+              pos = 0;
+              throw new NotModifiedException();
+            }
+          }
           pos = 0;
         }
         buffer[pos++] = (byte) i;
           pos = 0;
         }
         buffer[pos++] = (byte) i;
@@ -659,8 +670,14 @@ public class AcceleratorFilter implements Filter {
 
         committed = true;
         /** Dekoration nur beim ersten Schreib-Schub anstoßen */
 
         committed = true;
         /** Dekoration nur beim ersten Schreib-Schub anstoßen */
-        if (pos == size)
-          cacheControl.decorate(request, response);
+        if (pos == size) {
+          if (!cacheControl.decorate(request, response)) {
+            zipped = false;
+            os = null;
+            pos = 0;
+            throw new NotModifiedException();
+          }
+        }
         out().write(buffer, 0, pos);
         out().flush();
         pos = 0;
         out().write(buffer, 0, pos);
         out().flush();
         pos = 0;
@@ -671,7 +688,8 @@ public class AcceleratorFilter implements Filter {
         if (size == 0) {
           committed = true;
           zipped = false;
         if (size == 0) {
           committed = true;
           zipped = false;
-          cacheControl.decorate(request, response);
+          if (!cacheControl.decorate(request, response))
+            throw new NotModifiedException();
           sos.close();
         }
         else {
           sos.close();
         }
         else {
@@ -682,3 +700,5 @@ public class AcceleratorFilter implements Filter {
     }
   }
 }
     }
   }
 }
+
+class NotModifiedException extends IOException {}
\ No newline at end of file