okhttp: Is there an order of precedence for respon...
# squarelibraries
c
okhttp: Is there an order of precedence for response caching headers? e.g. I'm getting both
ETag
and
Last-Modified:
but it seems like the follow up request uses ETAG in the response. Whereas my server team really wants us to use Last-Modified.
Are you expecting if-modified-since in request?
j
Don’t send an etag if you don’t want the client to use it!
1
g
@jessewilson how to handle retro-compat for some clients expecting etag then? Any solution but a new endpoint?
y
You can add an interceptor to change the response headers.
👍 1
j
Why does the server send an etag if they don’t want you to use it?
c
Thank you for the rfc link and for finding where the etag is preferred Yuri, and thank you for confirming jesse. I will screenshot that message and let them know that the library author suggests that... which is funny... because thats what i told them yesterday. "don't send the header if you don't want the client to use it" 😂
y
I think the RFC says we SHOULD send both. I need to confirm if we do
c
It does not seem like we send both. Here is the original 200'ing response
Copy code
HTTP/1.1 200 OK
Date: Wed, 20 Mar 2024 17:25:11 GMT
Server: Apache/2.4.41 (Ubuntu)
X-Powered-By: Express
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
Last-Modified: 2023-09-12T15:48:48.000Z
Content-Type: application/json; charset=utf-8
Content-Length: 455
ETag: FOO
Keep-Alive: timeout=5, max=99
Connection: Keep-Alive
and here is the subsequent request
Copy code
GET /api/blah
HTTP/1.1
Authorize: BLAH
Host: <http://blah.com|blah.com>
Connection: Keep-Alive
Accept-Encoding: gzip
User-Agent: okhttp/4.11.0
If-None-Match: FOO
y
Ill file a ticket to track. But I don't think it's breaking anything.
👍 1
c
Maybe a dumb question, but is there a good list of all cache headers? on mdn, it kinda makes it seem like etag is not really a header for caching since its not under the cache-control page. unless im misunderstanding something (completely possible) lol
Age Cache-Control Date ETag Expires Last-Modified If-None-Match If-Modified-Since
💵 2