public CacheEntry(String key, MultivaluedMap<String, String> headers, byte[] cached, int expires, String etag, String lastModified, MediaType mediaType) { this.key = key; this.cached = cached; this.expires = expires; this.mediaType = mediaType.toString(); this.headers = headers; if (etag != null || lastModified != null) { if (etag != null && lastModified != null) { validationHeaders = new Header[2]; validationHeaders[0] = new Header("If-Modified-Since", lastModified); validationHeaders[1] = new Header("If-None-Match", etag); } else if (etag != null) { validationHeaders = new Header[1]; validationHeaders[0] = new Header("If-None-Match", etag); } else if (lastModified != null) { validationHeaders = new Header[1]; validationHeaders[0] = new Header("If-Modified-Since", lastModified); } } }
public CacheEntry(String key, MultivaluedMap<String, String> headers, byte[] cached, int expires, String etag, String lastModified, MediaType mediaType) { this.key = key; this.cached = cached; this.expires = expires; this.mediaType = mediaType.toString(); this.headers = headers; if (etag != null || lastModified != null) { if (etag != null && lastModified != null) { validationHeaders = new Header[2]; validationHeaders[0] = new Header("If-Modified-Since", lastModified); validationHeaders[1] = new Header("If-None-Match", etag); } else if (etag != null) { validationHeaders = new Header[1]; validationHeaders[0] = new Header("If-None-Match", etag); } else if (lastModified != null) { validationHeaders = new Header[1]; validationHeaders[0] = new Header("If-Modified-Since", lastModified); } } }
public ClientResponse execute(ClientExecutionContext ctx) throws Exception { ClientRequest request = ctx.getRequest(); if (!request.getHttpMethod().equals("GET")) { return ctx.proceed(); } BrowserCache.Entry entry = getEntry(request); if (entry == null) { return cache(request, ctx.proceed()); } if (entry.expired()) { cache.remove(request.getUri(), entry.getMediaType()); BrowserCache.Header[] headers = entry.getValidationHeaders(); for (BrowserCache.Header header : headers) { request.header(header.getName(), header.getValue()); } return handleExpired(ctx, request, entry); } return createClientResponse(request, entry); }
public ClientResponse execute(ClientExecutionContext ctx) throws Exception { ClientRequest request = ctx.getRequest(); if (!request.getHttpMethod().equals("GET")) { return ctx.proceed(); } BrowserCache.Entry entry = getEntry(request); if (entry == null) { return cache(request, ctx.proceed()); } if (entry.expired()) { cache.remove(request.getUri(), entry.getMediaType()); BrowserCache.Header[] headers = entry.getValidationHeaders(); for (BrowserCache.Header header : headers) { request.header(header.getName(), header.getValue()); } return handleExpired(ctx, request, entry); } return createClientResponse(request, entry); }