appendQuotedWithSeparator(b, "private", buildListValue(header.getPrivateFields())); if (header.isNoCache()) { appendQuotedWithSeparator(b, "no-cache", buildListValue(header.getNoCacheFields()));
appendQuotedWithSeparator(b, "private", buildListValue(header.getPrivateFields())); if (header.isNoCache()) { appendQuotedWithSeparator(b, "no-cache", buildListValue(header.getNoCacheFields()));
if (value.isNoCache())
if (cc.isNoCache())
public void cacheIfPossible(ClientRequestContext request, ClientResponseContext response) throws IOException { String cc = (String) response.getHeaderString(HttpHeaders.CACHE_CONTROL); String exp = (String) response.getHeaderString(HttpHeaders.EXPIRES); int expires = -1; if (cc != null) { CacheControl cacheControl = CacheControl.valueOf(cc); if (cacheControl.isNoCache()) return; expires = cacheControl.getMaxAge(); } else if (exp != null) { Date date = DateUtil.parseDate(exp); expires = (int) ((date.getTime() - System.currentTimeMillis()) / 1000); } String lastModified = (String) response.getHeaderString(HttpHeaders.LAST_MODIFIED); String etag = (String) response.getHeaderString(HttpHeaders.ETAG); String contentType = (String) response.getHeaderString(HttpHeaders.CONTENT_TYPE); String accept = (String) request.getHeaderString(HttpHeaders.ACCEPT); byte[] cached = ReadFromStream.readFromStream(1024, response.getEntityStream()); // if Accept is present, use it, if not fallback to response Content-Type MediaType mediaType = accept != null ? MediaType.valueOf(accept) : MediaType.valueOf(contentType); final BrowserCache.Entry entry = cache.put(request.getUri().toString(), mediaType, response.getHeaders(), cached, expires, etag, lastModified); response.setEntityStream(new ByteArrayInputStream(cached)); }
if (cacheControl.isNoCache())
protected boolean isCacheControlValid(final ReaderInterceptorContext context, final CacheControl responseControl) { boolean valid = responseControl != null && !responseControl.isNoCache() && !responseControl.isNoStore(); if (valid) { String clientHeader = (String)context.getProperty(CacheControlClientRequestFilter.CLIENT_CACHE_CONTROL); CacheControl clientControl = clientHeader == null ? null : CacheControl.valueOf(clientHeader); if (clientControl != null && clientControl.isPrivate() != responseControl.isPrivate()) { valid = false; } } return valid; } }
protected boolean isCacheControlValid(final ReaderInterceptorContext context, final CacheControl responseControl) { boolean valid = responseControl != null && !responseControl.isNoCache() && !responseControl.isNoStore(); if (valid) { String clientHeader = (String)context.getProperty(CacheControlClientRequestFilter.CLIENT_CACHE_CONTROL); CacheControl clientControl = clientHeader == null ? null : CacheControl.valueOf(clientHeader); if (clientControl != null && clientControl.isPrivate() != responseControl.isPrivate()) { valid = false; } } return valid; } }
public ClientResponse cacheIfPossible(ClientRequest request, BaseClientResponse response) throws Exception { String cc = (String) response.getResponseHeaders().getFirst(HttpHeaders.CACHE_CONTROL); String exp = (String) response.getResponseHeaders().getFirst(HttpHeaders.EXPIRES); int expires = -1; if (cc != null) { CacheControl cacheControl = CacheControl.valueOf(cc); if (cacheControl.isNoCache()) return response; expires = cacheControl.getMaxAge(); } else if (exp != null) { Date date = DateUtil.parseDate(exp); expires = (int) ((date.getTime() - System.currentTimeMillis()) / 1000); } String lastModified = (String) response.getResponseHeaders().getFirst(HttpHeaders.LAST_MODIFIED); String etag = (String) response.getResponseHeaders().getFirst(HttpHeaders.ETAG); String contentType = (String) response.getResponseHeaders().getFirst(HttpHeaders.CONTENT_TYPE); byte[] cached = ReadFromStream.readFromStream(1024, response.getStreamFactory().getInputStream()); response.getStreamFactory().performReleaseConnection(); MediaType mediaType = MediaType.valueOf(contentType); final BrowserCache.Entry entry = cache.put(request.getUri(), mediaType, response.getResponseHeaders(), cached, expires, etag, lastModified); response.setStreamFactory(new CachedStreamFactory(entry)); return response; }
public ClientResponse cacheIfPossible(ClientRequest request, BaseClientResponse response) throws Exception { String cc = (String) response.getResponseHeaders().getFirst(HttpHeaders.CACHE_CONTROL); String exp = (String) response.getResponseHeaders().getFirst(HttpHeaders.EXPIRES); int expires = -1; if (cc != null) { CacheControl cacheControl = CacheControl.valueOf(cc); if (cacheControl.isNoCache()) return response; expires = cacheControl.getMaxAge(); } else if (exp != null) { Date date = DateUtil.parseDate(exp); expires = (int) ((date.getTime() - System.currentTimeMillis()) / 1000); } String lastModified = (String) response.getResponseHeaders().getFirst(HttpHeaders.LAST_MODIFIED); String etag = (String) response.getResponseHeaders().getFirst(HttpHeaders.ETAG); String contentType = (String) response.getResponseHeaders().getFirst(HttpHeaders.CONTENT_TYPE); byte[] cached = ReadFromStream.readFromStream(1024, response.getStreamFactory().getInputStream()); response.getStreamFactory().performReleaseConnection(); MediaType mediaType = MediaType.valueOf(contentType); final BrowserCache.Entry entry = cache.put(request.getUri(), mediaType, response.getResponseHeaders(), cached, expires, etag, lastModified); response.setStreamFactory(new CachedStreamFactory(entry)); return response; }
public void cacheIfPossible(ClientRequestContext request, ClientResponseContext response) throws IOException { String cc = (String) response.getHeaderString(HttpHeaders.CACHE_CONTROL); String exp = (String) response.getHeaderString(HttpHeaders.EXPIRES); int expires = -1; if (cc != null) { CacheControl cacheControl = CacheControl.valueOf(cc); if (cacheControl.isNoCache()) return; expires = cacheControl.getMaxAge(); } else if (exp != null) { Date date = DateUtil.parseDate(exp); expires = (int) ((date.getTime() - System.currentTimeMillis()) / 1000); } String lastModified = (String) response.getHeaderString(HttpHeaders.LAST_MODIFIED); String etag = (String) response.getHeaderString(HttpHeaders.ETAG); String contentType = (String) response.getHeaderString(HttpHeaders.CONTENT_TYPE); byte[] cached = ReadFromStream.readFromStream(1024, response.getEntityStream()); MediaType mediaType = MediaType.valueOf(contentType); final BrowserCache.Entry entry = cache.put(request.getUri().toString(), mediaType, response.getHeaders(), cached, expires, etag, lastModified); response.setEntityStream(new ByteArrayInputStream(cached)); }
@Test public void forCacheControl() { final Parser<CacheControl> parser = Parser.forCacheControl(); final CacheControl cc1 = createCacheControl(); cc1.setMaxAge(2000); final CacheControl cc2 = createCacheControl(); cc2.setNoCache(true); for (final CacheControl v : new CacheControl[] { cc1, cc2 }) { final String asString = parser.asString(v); final CacheControl valueOf = parser.valueOf(asString); assertThat(v.getMaxAge(), is(equalTo(valueOf.getMaxAge()))); assertThat(v.isNoCache(), is(equalTo(valueOf.isNoCache()))); } }
public void cacheIfPossible(ClientRequestContext request, ClientResponseContext response) throws IOException { String cc = (String) response.getHeaderString(HttpHeaders.CACHE_CONTROL); String exp = (String) response.getHeaderString(HttpHeaders.EXPIRES); int expires = -1; if (cc != null) { CacheControl cacheControl = CacheControl.valueOf(cc); if (cacheControl.isNoCache()) return; expires = cacheControl.getMaxAge(); } else if (exp != null) { Date date = DateUtil.parseDate(exp); expires = (int) ((date.getTime() - System.currentTimeMillis()) / 1000); } String lastModified = (String) response.getHeaderString(HttpHeaders.LAST_MODIFIED); String etag = (String) response.getHeaderString(HttpHeaders.ETAG); String contentType = (String) response.getHeaderString(HttpHeaders.CONTENT_TYPE); String accept = (String) request.getHeaderString(HttpHeaders.ACCEPT); byte[] cached = ReadFromStream.readFromStream(1024, response.getEntityStream()); // if Accept is present, use it, if not fallback to response Content-Type MediaType mediaType = accept != null ? MediaType.valueOf(accept) : MediaType.valueOf(contentType); final BrowserCache.Entry entry = cache.put(request.getUri().toString(), mediaType, response.getHeaders(), cached, expires, etag, lastModified); response.setEntityStream(new ByteArrayInputStream(cached)); }
@Test public void forCacheControl() { final Parser<CacheControl> parser = Parser.forCacheControl(); final CacheControl cc1 = createCacheControl(); cc1.setMaxAge(2000); final CacheControl cc2 = createCacheControl(); cc2.setNoCache(true); for (final CacheControl v : new CacheControl[] { cc1, cc2 }) { final String asString = parser.asString(v); final CacheControl valueOf = parser.valueOf(asString); assertThat(v.getMaxAge(), is(equalTo(valueOf.getMaxAge()))); assertThat(v.isNoCache(), is(equalTo(valueOf.isNoCache()))); } }
@Test public void forCacheControl() { final Parser<CacheControl> parser = Parser.forCacheControl(); final CacheControl cc1 = createCacheControl(); cc1.setMaxAge(2000); final CacheControl cc2 = createCacheControl(); cc2.setNoCache(true); for (final CacheControl v : new CacheControl[] { cc1, cc2 }) { final String asString = parser.asString(v); final CacheControl valueOf = parser.valueOf(asString); assertThat(v.getMaxAge(), is(equalTo(valueOf.getMaxAge()))); assertThat(v.isNoCache(), is(equalTo(valueOf.isNoCache()))); } }
appendWithParameters(buff, "private", header.getPrivateFields()); if (header.isNoCache()) { appendWithParameters(buff, "no-cache", header.getNoCacheFields());
public String toString(CacheControl header) { StringBuffer b = new StringBuffer(); if (header.isPrivate()) appendQuotedWithSeparator(b, "private", buildListValue(header.getPrivateFields())); if (header.isNoCache()) appendQuotedWithSeparator(b, "no-cache", buildListValue(header.getNoCacheFields())); if (header.isNoStore()) appendWithSeparator(b, "no-store"); if (header.isNoTransform()) appendWithSeparator(b, "no-transform"); if (header.isMustRevalidate()) appendWithSeparator(b, "must-revalidate"); if (header.isProxyRevalidate()) appendWithSeparator(b, "proxy-revalidate"); if (header.getMaxAge() != -1) appendWithSeparator(b, "max-age", header.getMaxAge()); if (header.getSMaxAge() != -1) appendWithSeparator(b, "s-maxage", header.getSMaxAge()); for (Map.Entry<String, String> e : header.getCacheExtension().entrySet()) { appendWithSeparator(b, e.getKey(), quoteIfWhitespace(e.getValue())); } return b.toString(); }
public String toString(CacheControl header) { StringBuffer b = new StringBuffer(); if (header.isPrivate()) appendQuotedWithSeparator(b, "private", buildListValue(header.getPrivateFields())); if (header.isNoCache()) appendQuotedWithSeparator(b, "no-cache", buildListValue(header.getNoCacheFields())); if (header.isNoStore()) appendWithSeparator(b, "no-store"); if (header.isNoTransform()) appendWithSeparator(b, "no-transform"); if (header.isMustRevalidate()) appendWithSeparator(b, "must-revalidate"); if (header.isProxyRevalidate()) appendWithSeparator(b, "proxy-revalidate"); if (header.getMaxAge() != -1) appendWithSeparator(b, "max-age", header.getMaxAge()); if (header.getSMaxAge() != -1) appendWithSeparator(b, "s-maxage", header.getSMaxAge()); for (Map.Entry<String, String> e : header.getCacheExtension().entrySet()) { appendWithSeparator(b, e.getKey(), quoteIfWhitespace(e.getValue())); } return b.toString(); }
appendQuotedWithSeparator(b, "private", buildListValue(header.getPrivateFields())); if (header.isNoCache()) { appendQuotedWithSeparator(b, "no-cache", buildListValue(header.getNoCacheFields()));
appendQuotedWithSeparator(b, "private", buildListValue(header.getPrivateFields())); if (header.isNoCache()) { appendQuotedWithSeparator(b, "no-cache", buildListValue(header.getNoCacheFields()));