Skip to content

Commit ce50296

Browse files
committed
KTOR-5868 Fix the delimiter for a Cookie name-value pairs (#3739)
(cherry picked from commit 67e4f4e)
1 parent d17b3d9 commit ce50296

File tree

2 files changed

+14
-1
lines changed
  • ktor-client
    • ktor-client-core/common/src/io/ktor/client/engine
    • ktor-client-tests/common/test/io/ktor/client/tests/plugins

2 files changed

+14
-1
lines changed

ktor-client/ktor-client-core/common/src/io/ktor/client/engine/Utils.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ public fun mergeHeaders(
4747
block(key, value)
4848
}
4949
} else {
50-
block(key, values.joinToString(","))
50+
val separator = if (HttpHeaders.Cookie == key) "; " else ","
51+
block(key, values.joinToString(separator))
5152
}
5253
}
5354

ktor-client/ktor-client-tests/common/test/io/ktor/client/tests/plugins/CookiesTest.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,5 +246,17 @@ class CookiesTest : ClientLoader() {
246246
}
247247
}
248248

249+
@Test
250+
fun testSeparatedBySemicolon() = clientTests(listOf("Js")) {
251+
test { client ->
252+
client.get("$TEST_HOST/encoded") {
253+
cookie("firstCookie", "first")
254+
header("Cookie", "secondCookie=second")
255+
}.bodyAsText().also {
256+
assertEquals("firstCookie=first; secondCookie=second", it)
257+
}
258+
}
259+
}
260+
249261
private suspend fun HttpClient.getId() = cookies(hostname)["id"]!!.value.toInt()
250262
}

0 commit comments

Comments
 (0)