/** * Sets HTTP headers that instruct the browser to cache content. Implementations should take care * to use cache-busting techniques on the url if caching for a long period of time. * * @param response The HTTP response * @param ttl The time to cache for, in seconds. If 0, then insure that * this object is not cached. */ public static void setCachingHeaders(HttpServletResponse response, int ttl) { setCachingHeaders(response, ttl, false); }
/** * Sets HTTP headers that instruct the browser to cache content. Implementations should take care * to use cache-busting techniques on the url if caching for a long period of time. * * @param response The HTTP response * @param noProxy True if you don't want the response to be cacheable by proxies. */ public static void setCachingHeaders(HttpServletResponse response, boolean noProxy) { setCachingHeaders(response, defaultTtl, noProxy); }
/** * Sets HTTP headers that instruct the browser to cache content. Implementations should take care * to use cache-busting techniques on the url if caching for a long period of time. * * @param response The HTTP response * @param noProxy True if you don't want the response to be cacheable by proxies. */ public static void setCachingHeaders(HttpServletResponse response, boolean noProxy) { setCachingHeaders(response, defaultTtl, noProxy); }
/** * Sets HTTP headers that instruct the browser to cache content. Implementations should take care * to use cache-busting techniques on the url if caching for a long period of time. * * @param response The HTTP response * @param ttl The time to cache for, in seconds. If 0, then insure that * this object is not cached. */ public static void setCachingHeaders(HttpServletResponse response, int ttl) { setCachingHeaders(response, ttl, false); }
/** * Sets HTTP headers that instruct the browser to cache content. Implementations should take care * to use cache-busting techniques on the url if caching for a long period of time. * * @param response The HTTP response * @param noProxy True if you don't want the response to be cacheable by proxies. */ public static void setCachingHeaders(HttpServletResponse response, boolean noProxy) { setCachingHeaders(response, defaultTtl, noProxy); }
/** * Sets HTTP headers that instruct the browser to cache content. Implementations should take care * to use cache-busting techniques on the url if caching for a long period of time. * * @param response The HTTP response * @param ttl The time to cache for, in seconds. If 0, then insure that * this object is not cached. */ public static void setCachingHeaders(HttpServletResponse response, int ttl) { setCachingHeaders(response, ttl, false); }
public static void copyResponseToServlet(HttpResponse response, HttpServletResponse servletResponse) throws IOException { servletResponse.setStatus(response.getHttpStatusCode()); servletResponse.setContentLength(response.getContentLength()); for (Map.Entry<String, String> header : response.getHeaders().entries()) { servletResponse.addHeader(header.getKey(), header.getValue()); } HttpUtil.setCachingHeaders(servletResponse, (int)(response.getCacheTtl() / 1000L)); IOUtils.copy(response.getResponse(), servletResponse.getOutputStream()); }
public static void copyToServletResponseAndOverrideCacheHeaders( HttpResponse response, HttpServletResponse servletResponse) throws IOException { copyHeadersAndStatusToServletResponse(response, servletResponse); HttpUtil.setCachingHeaders(servletResponse, (int)(response.getCacheTtl() / 1000L)); copyContentToServletResponse(response, servletResponse); }
@Test public void testSetCachingHeadersWithTtlAndNoProxy() { int ttl = 20; HttpUtil.setCachingHeaders(recorder, ttl, true); checkCacheControlHeaders(testStartTime, recorder, ttl, true); }
@Test public void testSetCachingHeadersWithTtlAndNoProxy() { int ttl = 20; HttpUtil.setCachingHeaders(recorder, ttl, true); checkCacheControlHeaders(testStartTime, recorder, ttl, true); }
@Test public void testSetCachingHeadersWithTtlAndNoProxy() { int ttl = 20; HttpUtil.setCachingHeaders(recorder, ttl, true); checkCacheControlHeaders(testStartTime, recorder, ttl, true); }
@Test public void testSetCachingHeadersNoCache() { HttpUtil.setCachingHeaders(recorder, 0); checkCacheControlHeaders(testStartTime, recorder, 0, true); }
@Test public void testSetCachingHeadersFixedTtl() { int ttl = 10; HttpUtil.setCachingHeaders(recorder, ttl); checkCacheControlHeaders(testStartTime, recorder, ttl, false); }
@Test public void testSetCachingHeadersAllowProxy() { HttpUtil.setCachingHeaders(recorder, false); checkCacheControlHeaders(testStartTime, recorder, HttpUtil.getDefaultTtl(), false); }
@Test public void testSetCachingHeaders() { HttpUtil.setCachingHeaders(recorder); checkCacheControlHeaders(testStartTime, recorder, HttpUtil.getDefaultTtl(), false); }
@Test public void testSetCachingHeaders() { HttpUtil.setCachingHeaders(recorder); checkCacheControlHeaders(testStartTime, recorder, HttpUtil.getDefaultTtl(), false); }
@Test public void testSetCachingHeadersAllowProxy() { HttpUtil.setCachingHeaders(recorder, false); checkCacheControlHeaders(testStartTime, recorder, HttpUtil.getDefaultTtl(), false); }
@Test public void testSetCachingHeadersNoProxy() { HttpUtil.setCachingHeaders(recorder, true); checkCacheControlHeaders(testStartTime, recorder, HttpUtil.getDefaultTtl(), true); }
@Test public void testSetCachingHeadersNoProxy() { HttpUtil.setCachingHeaders(recorder, true); checkCacheControlHeaders(testStartTime, recorder, HttpUtil.getDefaultTtl(), true); }
@Test public void testSetCachingHeaders() { HttpUtil.setCachingHeaders(recorder); checkCacheControlHeaders(testStartTime, recorder, HttpUtil.getDefaultTtl(), false); }