Install a JVM-wide cache, then opt one connection out of it
Install a JVM-wide cache, then opt one connection out of it
Answer
ResponseCache.setDefault(new DiskCache()); URLConnection conn = url.openConnection(); conn.setUseCaches(false); try (InputStream in = conn.getInputStream()) { in.transferTo(System.out); }
setDefault installs one cache for the whole JVM, exactly as CookieHandler.setDefault installs one cookie store. setUseCaches(false) excuses a single connection from it, and being a configuration setter it must run before the first read or it throws IllegalStateException.
Harold 4e ch7 §Caches; RFC 7234 §5.2 Cache-Control; §4.3 Validation