@Test public void makeSureHEADRequestUpdatesCacheI304() throws Exception { LocalDateTime base = LocalDateTime.of(2010, 2, 3, 10, 0, 0, 0); Headers headers = new Headers(); CacheControl cacheControl = new CacheControl.Builder().maxAge(50).withPrivate().build(); headers = headers.add(cacheControl.toHeader()); headers = headers.add(HeaderUtils.toHttpDate(HeaderConstants.DATE, base)); headers = headers.withETag(new Tag("foo")); HTTPResponse cachedResponse = new HTTPResponse(createClosedPayload(), Status.OK, headers); CacheItem item = new DefaultCacheItem(cachedResponse) { @Override public boolean isStale(LocalDateTime requestTime) { return true; } }; when(cacheStorage.get(isA(HTTPRequest.class))).thenReturn(item); HTTPRequest request = new HTTPRequest(REQUEST_URI, HTTPMethod.HEAD); base = base.plusHours(1); HTTPResponse HEADResponse = new HTTPResponse(Status.NOT_MODIFIED, new Headers().withDate(base).withCacheControl(cacheControl)); when(responseResolver.resolve(request)).thenReturn(HEADResponse); when(cacheStorage.update(isA(HTTPRequest.class), isA(HTTPResponse.class))).thenReturn(new HTTPResponse(createClosedPayload(), Status.OK, HEADResponse.getHeaders())); HTTPResponse response = cache.execute(request); verify(cacheStorage, never()).invalidate(REQUEST_URI); verify(cacheStorage, atLeastOnce()).update(isA(HTTPRequest.class), isA(HTTPResponse.class)); assertFalse(response.hasPayload()); }
public HTTPResponse execute(final HTTPRequest request) { return execute(request, helper.isEndToEndReloadRequest(request)); }
HTTPCache { public HTTPResponse execute(final HTTPRequest request) { return execute(request, helper.isEndToEndReloadRequest(request)); } }
HTTPCache { public HTTPResponse execute(final HTTPRequest request) { return execute(request, helper.isEndToEndReloadRequest(request)); } HTTPCache(CacheStorage storage, ResponseResolver resolver); }
HTTPCache { public HTTPResponse execute(final HTTPRequest request) { return execute(request, helper.isEndToEndReloadRequest(request)); } HTTPCache(CacheStorage storage, ResponseResolver resolver); void clear(); CacheStorage getStorage(); ResponseResolver getResolver(); CacheStatistics getStatistics(); HTTPResponse execute(final HTTPRequest request); HTTPResponse executeRefresh(final HTTPRequest request); void shutdown(); boolean isTranslateHEADToGET(); void setTranslateHEADToGET(boolean translateHEADToGET); }
HTTPCache { public HTTPResponse execute(final HTTPRequest request) { return execute(request, helper.isEndToEndReloadRequest(request)); } HTTPCache(CacheStorage storage, ResponseResolver resolver); void clear(); CacheStorage getStorage(); ResponseResolver getResolver(); CacheStatistics getStatistics(); HTTPResponse execute(final HTTPRequest request); HTTPResponse executeRefresh(final HTTPRequest request); void shutdown(); boolean isTranslateHEADToGET(); void setTranslateHEADToGET(boolean translateHEADToGET);  }