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

Rafał Kuźmiński

10/23/2023, 3:40 PM
Ktor Client is ignoring all header values but first in Vary Keys creation. Is this desired behaviour? In our project it breaks cache possibilities. It was tested on Ktor 2.3.0. Current code looks like this:
Copy code
internal fun HttpResponse.varyKeys(): Map<String, String> {
    val validationKeys = vary() ?: return emptyMap()

    val result = mutableMapOf<String, String>()
    val requestHeaders = call.request.headers

    for (key in validationKeys) {
        result[key] = requestHeaders[key] ?: ""
    }

    return result
}
I think that we should not take first value of requestHeaders, but all of them and join into single string:
Copy code
result[key] = requestHeaders.getAll(key).joinToString(";")
to match "mergedHeadersLookup" method which is used when Ktor is trying to retrieve value from cache
a

Aleksei Tirman [JB]

10/24/2023, 6:58 AM
Can you please file an issue with the code snippet attached?
3 Views