Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,15 @@ private class FileCacheStorage(
channel.writeFully(cache.body)
}

/**
* Deserialize a single CachedResponseData from the provided ByteReadChannel.
*
* Reads the cached-entry fields in the stored binary format: request URL, HTTP status and version,
* headers, request/response/expiration timestamps, vary keys (converted to lowercase), and the body bytes.
*
* @param channel Source channel positioned at the start of a serialized cache entry.
* @return The reconstructed CachedResponseData instance.
*/
Comment on lines +208 to +216
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/**
* Deserialize a single CachedResponseData from the provided ByteReadChannel.
*
* Reads the cached-entry fields in the stored binary format: request URL, HTTP status and version,
* headers, request/response/expiration timestamps, vary keys (converted to lowercase), and the body bytes.
*
* @param channel Source channel positioned at the start of a serialized cache entry.
* @return The reconstructed CachedResponseData instance.
*/
/**
* Deserialize a single [CachedResponseData] from the provided [ByteReadChannel].
*
* Reads the cached-entry fields in the stored binary format: request URL, HTTP status and version,
* headers, request/response/expiration timestamps, vary keys (converted to lowercase), and the body bytes.
*
* @param channel Source channel positioned at the start of a serialized cache entry.
* @return The reconstructed [CachedResponseData] instance.
*/

private suspend fun readCache(channel: ByteReadChannel): CachedResponseData {
val url = channel.readUTF8Line()!!
val status = HttpStatusCode(channel.readInt(), channel.readUTF8Line()!!)
Expand All @@ -222,7 +231,7 @@ private class FileCacheStorage(
val varyKeysCount = channel.readInt()
val varyKeys = buildMap {
for (j in 0 until varyKeysCount) {
val key = channel.readUTF8Line()!!
val key = channel.readUTF8Line()!!.lowercase()
val value = channel.readUTF8Line()!!
put(key, value)
}
Expand All @@ -242,4 +251,4 @@ private class FileCacheStorage(
body = body
)
}
}
}
15 changes: 14 additions & 1 deletion ktor-test-server/src/main/kotlin/test/server/tests/Cache.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ import java.util.concurrent.atomic.AtomicInteger

internal val counter = AtomicInteger(0)

/**
* Registers test routes under `/cache` that exercise caching and conditional header behaviors.
*
* Installs the `CachingHeaders` and `ConditionalHeaders` plugins and declares endpoints used in tests:
* handlers for various `Cache-Control` directives, `Expires`, `ETag`, `Last-Modified`, and `Vary`
* header scenarios, including endpoints that return 304 Not Modified responses and case-sensitive
* vary-header behaviors.
*/
internal fun Application.cacheTestServer() {
routing {
route("/cache") {
Expand Down Expand Up @@ -149,6 +157,11 @@ internal fun Application.cacheTestServer() {
else -> error("Should not be invoked")
}
}

get("/vary-header-not-modified") {
call.response.header(HttpHeaders.Vary, HttpHeaders.AcceptLanguage)
call.respond(HttpStatusCode.NotModified)
}
}
}
}
}