@Test public void testMixedImplementationsScenario() throws Exception { stubFor(getPath().willReturn(aResponse().withStatus(200).withBody("init") .withHeader("Last-Modified", "Fri, 4 Oct 2019 18:58:30 GMT"))); var source = new HttpSource(client()); var id = Http.url(defaultURL(), CacheControlStrategy.ETAG); var loadedResource = source.load(id); assertThat(IOUtils.toString(loadedResource.getInputStream(), UTF_8)).isEqualTo("init"); assertThat(loadedResource.getVersion()).isSameAs(SourceVersion.EMPTY); assertThat(source.loadIfModified(id, loadedResource.getVersion())).isNotNull(); }
@Override public LoadedResource loadIfModified(HttpResourceId resourceId, SourceVersion version) { var cacheControl = resourceId.getCacheControl(); if (version == SourceVersion.EMPTY || cacheControl == CacheControlStrategy.NONE) { return loadResource(resourceId); } else if (cacheControl == CacheControlStrategy.ETAG) { return loadResource(resourceId, singletonList(new BasicHeader(HttpHeaders.IF_NONE_MATCH, version.val().toString()))); } else if (cacheControl == CacheControlStrategy.IF_MODIFIED_SINCE) { return loadResource(resourceId, singletonList(new BasicHeader(HttpHeaders.IF_MODIFIED_SINCE, lastModifiedValue(version.val())))); } else if (cacheControl == CacheControlStrategy.LAST_MODIFIED_HEAD || cacheControl == CacheControlStrategy.ETAG_HEAD) { if (isChanged(resourceId, version)) { return loadResource(resourceId); } } return null; }
HttpSource extends AbstractSource<HttpResourceId> implements NonListenableSource<HttpResourceId> { @Override public LoadedResource loadIfModified(HttpResourceId resourceId, SourceVersion version) { var cacheControl = resourceId.getCacheControl(); if (version == SourceVersion.EMPTY || cacheControl == CacheControlStrategy.NONE) { return loadResource(resourceId); } else if (cacheControl == CacheControlStrategy.ETAG) { return loadResource(resourceId, singletonList(new BasicHeader(HttpHeaders.IF_NONE_MATCH, version.val().toString()))); } else if (cacheControl == CacheControlStrategy.IF_MODIFIED_SINCE) { return loadResource(resourceId, singletonList(new BasicHeader(HttpHeaders.IF_MODIFIED_SINCE, lastModifiedValue(version.val())))); } else if (cacheControl == CacheControlStrategy.LAST_MODIFIED_HEAD || cacheControl == CacheControlStrategy.ETAG_HEAD) { if (isChanged(resourceId, version)) { return loadResource(resourceId); } } return null; } }
HttpSource extends AbstractSource<HttpResourceId> implements NonListenableSource<HttpResourceId> { @Override public LoadedResource loadIfModified(HttpResourceId resourceId, SourceVersion version) { var cacheControl = resourceId.getCacheControl(); if (version == SourceVersion.EMPTY || cacheControl == CacheControlStrategy.NONE) { return loadResource(resourceId); } else if (cacheControl == CacheControlStrategy.ETAG) { return loadResource(resourceId, singletonList(new BasicHeader(HttpHeaders.IF_NONE_MATCH, version.val().toString()))); } else if (cacheControl == CacheControlStrategy.IF_MODIFIED_SINCE) { return loadResource(resourceId, singletonList(new BasicHeader(HttpHeaders.IF_MODIFIED_SINCE, lastModifiedValue(version.val())))); } else if (cacheControl == CacheControlStrategy.LAST_MODIFIED_HEAD || cacheControl == CacheControlStrategy.ETAG_HEAD) { if (isChanged(resourceId, version)) { return loadResource(resourceId); } } return null; } HttpSource(CloseableHttpClient client);  HttpSource(CloseableHttpClient client,
                      @NotNull Consumer<HttpRequestBase> requestInterceptor, boolean keepAlive); }
HttpSource extends AbstractSource<HttpResourceId> implements NonListenableSource<HttpResourceId> { @Override public LoadedResource loadIfModified(HttpResourceId resourceId, SourceVersion version) { var cacheControl = resourceId.getCacheControl(); if (version == SourceVersion.EMPTY || cacheControl == CacheControlStrategy.NONE) { return loadResource(resourceId); } else if (cacheControl == CacheControlStrategy.ETAG) { return loadResource(resourceId, singletonList(new BasicHeader(HttpHeaders.IF_NONE_MATCH, version.val().toString()))); } else if (cacheControl == CacheControlStrategy.IF_MODIFIED_SINCE) { return loadResource(resourceId, singletonList(new BasicHeader(HttpHeaders.IF_MODIFIED_SINCE, lastModifiedValue(version.val())))); } else if (cacheControl == CacheControlStrategy.LAST_MODIFIED_HEAD || cacheControl == CacheControlStrategy.ETAG_HEAD) { if (isChanged(resourceId, version)) { return loadResource(resourceId); } } return null; } HttpSource(CloseableHttpClient client);  HttpSource(CloseableHttpClient client,
                      @NotNull Consumer<HttpRequestBase> requestInterceptor, boolean keepAlive); @Override LoadedResource loadIfModified(HttpResourceId resourceId, SourceVersion version); @Override String describe(); }
HttpSource extends AbstractSource<HttpResourceId> implements NonListenableSource<HttpResourceId> { @Override public LoadedResource loadIfModified(HttpResourceId resourceId, SourceVersion version) { var cacheControl = resourceId.getCacheControl(); if (version == SourceVersion.EMPTY || cacheControl == CacheControlStrategy.NONE) { return loadResource(resourceId); } else if (cacheControl == CacheControlStrategy.ETAG) { return loadResource(resourceId, singletonList(new BasicHeader(HttpHeaders.IF_NONE_MATCH, version.val().toString()))); } else if (cacheControl == CacheControlStrategy.IF_MODIFIED_SINCE) { return loadResource(resourceId, singletonList(new BasicHeader(HttpHeaders.IF_MODIFIED_SINCE, lastModifiedValue(version.val())))); } else if (cacheControl == CacheControlStrategy.LAST_MODIFIED_HEAD || cacheControl == CacheControlStrategy.ETAG_HEAD) { if (isChanged(resourceId, version)) { return loadResource(resourceId); } } return null; } HttpSource(CloseableHttpClient client);  HttpSource(CloseableHttpClient client,
                      @NotNull Consumer<HttpRequestBase> requestInterceptor, boolean keepAlive); @Override LoadedResource loadIfModified(HttpResourceId resourceId, SourceVersion version); @Override String describe();  }