CachingHttpclient cannot ignore "Cache-Control: no-cache" header

I am using ApacheHttpClient caching to request REST APIs from Java code.

I want to cache some HTTP response despite receiving the "Cache-Control: no-cache" header, which causes the caching of the HttpClient to not cache the file.

With a standalone HTTP proxy like squid, mod_cache ..., I could tweak the config to ignore these headers and override the default behavior.

I would rather not look for a standalone http proxy, but rather use 100% Java code.

  • is there another http client that will offer more control over caching?
  • Is it possible to implement a middleware / proxy that will rewrite the headers?
  • Can I fix HttpClient caching via inheritance?
+3


source to share


1 answer


The request is denied CachedResponseSuitabilityChecker

in the method canCachedResponseBeUsed

. If you need different behavior for the class to implement your own version, then use the long constructor forcachingHttpClient



CachingHttpClient(HttpClient backend, 
     CacheValidityPolicy validityPolicy,
     ResponseCachingPolicy responseCachingPolicy,
     HttpCache responseCache,
     CachedHttpResponseGenerator responseGenerator,
     CacheableRequestPolicy cacheableRequestPolicy,
     CachedResponseSuitabilityChecker suitabilityChecker, 
     ConditionalRequestBuilder conditionalRequestBuilder, 
     ResponseProtocolCompliance responseCompliance, 
     RequestProtocolCompliance requestCompliance) 

      

+2


source







All Articles