Skip to content

Commit 4e4dfbb

Browse files
fru1tworldbjhham
authored andcommitted
KTOR-9168 Add regression test for case-insensitive Set-Cookie merging in CIO
1 parent e02c742 commit 4e4dfbb

1 file changed

Lines changed: 52 additions & 0 deletions

File tree

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright 2014-2026 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
package io.ktor.client.engine.cio
6+
7+
import io.ktor.client.*
8+
import io.ktor.client.request.*
9+
import io.ktor.http.*
10+
import kotlinx.coroutines.test.runTest
11+
import java.net.ServerSocket
12+
import java.net.SocketException
13+
import kotlin.concurrent.thread
14+
import kotlin.test.Test
15+
import kotlin.test.assertEquals
16+
17+
class CookieHeaderCaseTest {
18+
19+
@Test
20+
fun `CIO preserves Set-Cookie headers regardless of case`() = runTest {
21+
HttpClient(CIO).use { client ->
22+
ServerSocket(0).use { server ->
23+
val thread = thread {
24+
try {
25+
server.accept().use { socket ->
26+
socket.getOutputStream().let { out ->
27+
out.write(
28+
(
29+
"HTTP/1.1 200 OK\r\n" +
30+
"Content-Length: 0\r\n" +
31+
"Set-Cookie: first=1\r\n" +
32+
"set-cookie: second=2\r\n" +
33+
"\r\n"
34+
).toByteArray()
35+
)
36+
out.flush()
37+
}
38+
}
39+
} catch (_: SocketException) {
40+
}
41+
}
42+
43+
val response = client.get("http://localhost:${server.localPort}/")
44+
assertEquals(
45+
listOf("first=1", "second=2"),
46+
response.headers.getAll(HttpHeaders.SetCookie)
47+
)
48+
thread.join()
49+
}
50+
}
51+
}
52+
}

0 commit comments

Comments
 (0)