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;
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 {
case HttpServletResponse.SC_PARTIAL_CONTENT: // 206
/** Normale Antwort! Antwort dekorieren... */
break;
+ case HttpServletResponse.SC_MOVED_PERMANENTLY: // 301
+ case HttpServletResponse.SC_MOVED_TEMPORARILY: // 302
+ case HttpServletResponse.SC_SEE_OTHER: // 303
+ case HttpServletResponse.SC_NOT_MODIFIED: // 304
+ case HttpServletResponse.SC_USE_PROXY: // 305
+ case HttpServletResponse.SC_TEMPORARY_REDIRECT: // 307
+ /** Redirect-Antwort! Antwort dekodieren... */
+ // TODO: Kann das wirklich nicht zu Protokoll-Verletzungen führen?
+ break;
case HttpServletResponse.SC_BAD_REQUEST: // 400
case HttpServletResponse.SC_UNAUTHORIZED: // 401
case HttpServletResponse.SC_PAYMENT_REQUIRED: // 402
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<String,String> headers = handle.getAdditionalHeaders(request);
}
int cacheSeconds = handle.getCacheSeconds(request);
- if (cacheSeconds < 1) {
+ if (cacheSeconds < 0) {
log.debug("{}: caching disabled!", url);
response.setDateHeader(Headers.HEADER_DATE, handle.getTimestamp());
response.setDateHeader(Headers.HEADER_EXPIRES, 0);
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;
}
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);
}
- 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<String, String> cacheControlMap);
- Map<String,String> getAdditionalHeaders(HttpServletRequest request);
- }
-
-
class ReflectionCacheMethodHandle implements CacheMethodHandle {
private Object handler;
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;
- eTag = "";
/** Class-Level-Annotations auslesen */
for (Annotation annotation : handler.getClass().getAnnotations()) {
}
+ @Override
+ public boolean isZipped() {
+ return zipped;
+ }
+
@Override
public long getTimestamp() {
return now;