https://kotlinlang.org logo
#ktor
Title
# ktor
h

harry248

04/05/2022, 6:39 AM
Anyone got Ktor Client (2.0.0-beta1) to force a result from http cache using an
only-if-cached
cache control header? Ktor always responds with status code 504 even if there is a non-stale result in cache.
a

Aleksei Tirman [JB]

04/05/2022, 8:18 AM
Could you please share a code snippet to illustrate your issue?
h

harry248

04/05/2022, 8:33 AM
Configure the client engine with:
Copy code
install(HttpCache)
Send some request:
Copy code
httpClient.get("SOME_URL") {
    header(HttpHeaders.CacheControl, "only-if-cached")
}
Shouldn’t fail with status code 504 if there is a response in the http cache, but it does.
a

Aleksei Tirman [JB]

04/05/2022, 8:50 AM
Could you please describe what should be returned from a server for
SOME_URL
endpoint or give a link to public resource?
h

harry248

04/05/2022, 10:21 AM
In our case, it’s a private REST API that delivers JSON. The response contains correct ETag and Cache-Control headers to work properly with the HttpCache.
a

Aleksei Tirman [JB]

04/06/2022, 9:13 AM
Is it about Ktor client for the browser JS target?
h

harry248

04/06/2022, 10:11 AM
No Android / iOS