I misinterpreted the HTTP protocol. In this case, the server's decision to return a 304 status code was incorrect because there was a change in the metadata, even though there was no change in the payload.
Just to clarify, does this mean that when there is a change in either the payload or metadata, the server has to return a 200 status code with the payload and metadata? Thank you for clarifying doubts, Sneha On Wed, Nov 8, 2023 at 11:54 AM Oleg Kalnichevski <ol...@apache.org> wrote: > On 08/11/2023 15:58, Sneha Murganoor wrote: > > Thanks for the reply. Yes we understand that when an entry in cache is > > stale, we make conditional get requests. We are wondering if there is way > > we dont make conditional get instead just make unconditional get call, > > since AWS S3 returns as 304 status code even when there is header removed > > from the metadata and my team's framework relies on these headers. > > > > The server is clearly wrong and in violation of the HTTP protocol. It > should never respond with 304 if the resource representation data or > resource _metadata_ have changed. > > > > I was thinking of having an attribute (say noConditionalCalls) in cache > > config which on max-age simply makes a get call. > > > https://hc.apache.org/httpcomponents-client-5.2.x/current/httpclient5-cache/apidocs/org/apache/hc/client5/http/impl/cache/CacheConfig.html > > > > You see, we cannot provide a config parameter for each and every broken > server out there. Your best course should be fixing the problem on the > server side. > > Oleg > > > I look for the presence of this attribute here > > > https://github.com/apache/httpcomponents-client/blob/master/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CachingExec.java#L317 > > and decide that i build unconditional get request. > > > > Thanks > > Sneha > > > > On Tue, Nov 7, 2023 at 2:18 PM Oleg Kalnichevski <ol...@apache.org> > wrote: > > > >> On 07/11/2023 17:27, Sneha Murganoor wrote: > >>> Use case: We have Caching Apache Http Client calling s3 backend. When > >>> metadata (http headers) changes with no changes in payload, s3 sends us > >>> "304 NOT Modified" status code with current modified headers. But > apache > >>> reading 304 merges previous headers in cache with headers in response. > So > >>> when a particular header is removed from a 304 response, Apache still > >> adds > >>> this to the response which they get from cache in mergeHeaders method > >>> CacheUpdateHandler class. > >>> > >> > >> HttpClient does so because it is expected to according to the HTTP spec. > >> > >> > >> > https://www.rfc-editor.org/rfc/rfc9111.html#name-updating-stored-header-fiel > >> > >>> > >>> RevalidateCacheEntry merges headers from cache which do not exist any > >> more, > >>> Is there a way that we don't revalidateCacheEntry when we are past > >> max-age > >>> set in cache and just call the backend? > >>> > >> > >> Usually executing a conditional request and letting the origin server > >> decide whether to send a new resource representation (200) or update the > >> existing one (304) is more efficient and this is way HttpClient does. I > >> am not aware of a standard way of accomplishing what you are asking by > >> using request Cache-Control options. > >> > >> Oleg > >> > >> --------------------------------------------------------------------- > >> To unsubscribe, e-mail: httpclient-users-unsubscr...@hc.apache.org > >> For additional commands, e-mail: httpclient-users-h...@hc.apache.org > >> > >> > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: httpclient-users-unsubscr...@hc.apache.org > For additional commands, e-mail: httpclient-users-h...@hc.apache.org > >