https://kotlinlang.org logo
#squarelibraries
Title
# squarelibraries
c

Colton Idle

03/19/2024, 8:18 PM
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

jessewilson

03/20/2024, 12:58 AM
Don’t send an etag if you don’t want the client to use it!
1
g

glureau

03/20/2024, 8:28 AM
@jessewilson how to handle retro-compat for some clients expecting etag then? Any solution but a new endpoint?
y

yschimke

03/20/2024, 8:28 AM
You can add an interceptor to change the response headers.
👍 1
j

jessewilson

03/20/2024, 11:00 AM
Why does the server send an etag if they don’t want you to use it?
c

Colton Idle

03/20/2024, 1:36 PM
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

yschimke

03/20/2024, 1:51 PM
I think the RFC says we SHOULD send both. I need to confirm if we do
c

Colton Idle

03/20/2024, 5:27 PM
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

yschimke

03/20/2024, 6:50 PM
Ill file a ticket to track. But I don't think it's breaking anything.
👍 1
c

Colton Idle

03/20/2024, 8:10 PM
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
8 Views