From ce50296f80d9af1189c91a1e746ea24b765f80a0 Mon Sep 17 00:00:00 2001 From: Mariia Skripchenko <61115099+marychatte@users.noreply.github.com> Date: Wed, 30 Aug 2023 12:30:29 +0200 Subject: [PATCH] KTOR-5868 Fix the delimiter for a Cookie name-value pairs (#3739) (cherry picked from commit 67e4f4e67fd8f4e1354213550e8a445105e549d1) --- .../common/src/io/ktor/client/engine/Utils.kt | 3 ++- .../test/io/ktor/client/tests/plugins/CookiesTest.kt | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/ktor-client/ktor-client-core/common/src/io/ktor/client/engine/Utils.kt b/ktor-client/ktor-client-core/common/src/io/ktor/client/engine/Utils.kt index 0af8e88e56f..101c036852d 100644 --- a/ktor-client/ktor-client-core/common/src/io/ktor/client/engine/Utils.kt +++ b/ktor-client/ktor-client-core/common/src/io/ktor/client/engine/Utils.kt @@ -47,7 +47,8 @@ public fun mergeHeaders( block(key, value) } } else { - block(key, values.joinToString(",")) + val separator = if (HttpHeaders.Cookie == key) "; " else "," + block(key, values.joinToString(separator)) } } diff --git a/ktor-client/ktor-client-tests/common/test/io/ktor/client/tests/plugins/CookiesTest.kt b/ktor-client/ktor-client-tests/common/test/io/ktor/client/tests/plugins/CookiesTest.kt index fff0e130286..a0c29580ee5 100644 --- a/ktor-client/ktor-client-tests/common/test/io/ktor/client/tests/plugins/CookiesTest.kt +++ b/ktor-client/ktor-client-tests/common/test/io/ktor/client/tests/plugins/CookiesTest.kt @@ -246,5 +246,17 @@ class CookiesTest : ClientLoader() { } } + @Test + fun testSeparatedBySemicolon() = clientTests(listOf("Js")) { + test { client -> + client.get("$TEST_HOST/encoded") { + cookie("firstCookie", "first") + header("Cookie", "secondCookie=second") + }.bodyAsText().also { + assertEquals("firstCookie=first; secondCookie=second", it) + } + } + } + private suspend fun HttpClient.getId() = cookies(hostname)["id"]!!.value.toInt() }