From cc0eb77f0c8ebdc3b43f5167edacd8a19f8774f9 Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Thu, 31 May 2012 23:19:08 +0200 Subject: [PATCH] =?utf8?q?Ausgabe=20des=20Contents=20bei=20304=20unterdr?= =?utf8?q?=C3=BCckt?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../src/main/webapp/page-with-forward.jsp | 2 +- .../src/main/webapp/page-with-include.jsp | 2 +- .../src/main/webapp/simple-page.jsp | 2 +- .../juplo/cachecontrol/AcceleratorFilter.java | 34 +++++++++++++++---- 4 files changed, 30 insertions(+), 10 deletions(-) diff --git a/cachecontrol-example-jsp/src/main/webapp/page-with-forward.jsp b/cachecontrol-example-jsp/src/main/webapp/page-with-forward.jsp index 786dedad..35e49058 100644 --- a/cachecontrol-example-jsp/src/main/webapp/page-with-forward.jsp +++ b/cachecontrol-example-jsp/src/main/webapp/page-with-forward.jsp @@ -1,4 +1,4 @@ -<%@page contentType="text/html" pageEncoding="UTF-8" session="false"%> +<%@page contentType="text/html" pageEncoding="UTF-8" session="false" buffer="1kb" %> diff --git a/cachecontrol-example-jsp/src/main/webapp/page-with-include.jsp b/cachecontrol-example-jsp/src/main/webapp/page-with-include.jsp index 5c3af3e8..3347af77 100644 --- a/cachecontrol-example-jsp/src/main/webapp/page-with-include.jsp +++ b/cachecontrol-example-jsp/src/main/webapp/page-with-include.jsp @@ -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"%> diff --git a/cachecontrol-example-jsp/src/main/webapp/simple-page.jsp b/cachecontrol-example-jsp/src/main/webapp/simple-page.jsp index 9010d200..23e57793 100644 --- a/cachecontrol-example-jsp/src/main/webapp/simple-page.jsp +++ b/cachecontrol-example-jsp/src/main/webapp/simple-page.jsp @@ -1,4 +1,4 @@ -<%@page contentType="text/html" pageEncoding="UTF-8" session="false"%> +<%@page contentType="text/html" pageEncoding="UTF-8" session="false" buffer="1kb" %> diff --git a/cachecontrol/src/main/java/de/halbekunst/juplo/cachecontrol/AcceleratorFilter.java b/cachecontrol/src/main/java/de/halbekunst/juplo/cachecontrol/AcceleratorFilter.java index 63edfb59..f17ec8d3 100644 --- a/cachecontrol/src/main/java/de/halbekunst/juplo/cachecontrol/AcceleratorFilter.java +++ b/cachecontrol/src/main/java/de/halbekunst/juplo/cachecontrol/AcceleratorFilter.java @@ -67,8 +67,13 @@ public class AcceleratorFilter implements Filter { 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 @@ -644,8 +649,14 @@ public class AcceleratorFilter implements Filter { 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; @@ -659,8 +670,14 @@ public class AcceleratorFilter implements Filter { 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; @@ -671,7 +688,8 @@ public class AcceleratorFilter implements Filter { if (size == 0) { committed = true; zipped = false; - cacheControl.decorate(request, response); + if (!cacheControl.decorate(request, response)) + throw new NotModifiedException(); sos.close(); } else { @@ -682,3 +700,5 @@ public class AcceleratorFilter implements Filter { } } } + +class NotModifiedException extends IOException {} \ No newline at end of file -- 2.20.1