X-Git-Url: https://juplo.de/gitweb/?p=percentcodec;a=blobdiff_plain;f=cachecontrol%2Fsrc%2Fmain%2Fjava%2Fde%2Fhalbekunst%2Fjuplo%2Fcachecontrol%2FCacheControl.java;h=bf49a4530163aaa630d0fd88d7bd2c0f3d98876c;hp=2c909e81dc52b4312c20256a7365e7e70faaa757;hb=253f47d8c14c361b6828107668fdb1dcc235d560;hpb=e608524cacfb0e5faa8bb58f0921e188e0aa40b6 diff --git a/cachecontrol/src/main/java/de/halbekunst/juplo/cachecontrol/CacheControl.java b/cachecontrol/src/main/java/de/halbekunst/juplo/cachecontrol/CacheControl.java index 2c909e81..bf49a453 100644 --- a/cachecontrol/src/main/java/de/halbekunst/juplo/cachecontrol/CacheControl.java +++ b/cachecontrol/src/main/java/de/halbekunst/juplo/cachecontrol/CacheControl.java @@ -1,5 +1,6 @@ package de.halbekunst.juplo.cachecontrol; +import de.halbekunst.juplo.cachecontrol.AcceleratorFilter.AccelerationWrapper; import de.halbekunst.juplo.cachecontrol.annotations.CacheSeconds; import de.halbekunst.juplo.cachecontrol.annotations.Accepts; import de.halbekunst.juplo.cachecontrol.annotations.AdditionalHeaders; @@ -38,14 +39,13 @@ public class CacheControl { CacheControl.tl.set(handle); } - public void init(Object handler) throws NoSuchMethodException { - CacheControl.tl.set(new ReflectionCacheMethodHandle(handler)); + void init(Object handler, AccelerationWrapper wrapper) throws NoSuchMethodException { + CacheControl.tl.set(new ReflectionCacheMethodHandle(handler, wrapper == null ? false : wrapper.zipped)); } public boolean decorate( HttpServletRequest request, - HttpServletResponse response, - Object handler + HttpServletResponse response ) { try { @@ -93,13 +93,12 @@ public class CacheControl { case HttpServletResponse.SC_NOT_IMPLEMENTED: // 501 case HttpServletResponse.SC_SERVICE_UNAVAILABLE: // 503 case HttpServletResponse.SC_HTTP_VERSION_NOT_SUPPORTED: // 505 - return true; default: /** * Es ist nicht klar, was der Handler noch machen wird/muss: * Antwort nicht dekorieren und Kontroller an den Handler übergeben... */ - return false; + return true; } Map headers = handle.getAdditionalHeaders(request); @@ -131,6 +130,8 @@ public class CacheControl { response.addHeader(Headers.HEADER_CACHE_CONTROL, "no-store"); response.addHeader(Headers.HEADER_CACHE_CONTROL, "max-age=0"); response.addHeader(Headers.HEADER_CACHE_CONTROL, "s-max-age=0"); + if (handle.isZipped()) + response.addHeader(Headers.HEADER_CONTENT_ENCODING, "gzip"); return true; } @@ -221,6 +222,9 @@ public class CacheControl { log.debug("{}: first up!", url); + if (handle.isZipped()) + response.addHeader(Headers.HEADER_CONTENT_ENCODING, "gzip"); + /** HTTP/1.1-Caching-Header richtig setzen!! */ response.setDateHeader(Headers.HEADER_LAST_MODIFIED, lastModified); @@ -293,18 +297,6 @@ public class CacheControl { } - public interface CacheMethodHandle { - long getTimestamp(); - int accepts(HttpServletRequest request); - int getCacheSeconds(HttpServletRequest request); - long getLastModified(HttpServletRequest request); - String getETag(HttpServletRequest request); - boolean isETagWeak(); - void cacheControl(HttpServletRequest request, Map cacheControlMap); - Map getAdditionalHeaders(HttpServletRequest request); - } - - class ReflectionCacheMethodHandle implements CacheMethodHandle { private Object handler; @@ -326,11 +318,13 @@ public class CacheControl { private boolean isCacheControlMethodDefined; private boolean isAdditionalHeadersMethodDefined; private boolean weak; + private boolean zipped; - ReflectionCacheMethodHandle(Object handler) throws NoSuchMethodException { + ReflectionCacheMethodHandle(Object handler, boolean zipped) throws NoSuchMethodException { this.handler = handler; + this.zipped = zipped; cacheSeconds = CacheControl.this.defaultCacheSeconds; lastModified = CacheControl.this.defaultLastModified; @@ -436,6 +430,11 @@ public class CacheControl { } + @Override + public boolean isZipped() { + return zipped; + } + @Override public long getTimestamp() { return now;