-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve Jetty connection configuration by exposing a builder on the H…
…ttpConfiguration object
- Loading branch information
Showing
9 changed files
with
124 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
...r-jetty-jakarta/jvm/test/io/ktor/tests/server/jetty/jakarta/JettyHttpConfigurationTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright 2014-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
package io.ktor.tests.server.jetty.jakarta | ||
|
||
import io.ktor.client.* | ||
import io.ktor.client.request.* | ||
import io.ktor.http.* | ||
import io.ktor.server.engine.* | ||
import io.ktor.server.jetty.jakarta.* | ||
import io.ktor.server.response.* | ||
import io.ktor.server.routing.* | ||
import kotlinx.coroutines.test.* | ||
import java.net.* | ||
import kotlin.random.* | ||
import kotlin.test.* | ||
|
||
class JettyHttpConfigurationTest { | ||
|
||
private fun findFreePort() = ServerSocket(0).use { it.localPort } | ||
|
||
@Test | ||
fun `test HttpConfiguration with request header size example`() = runTest { | ||
val serverPort = findFreePort() | ||
|
||
embeddedServer(Jetty, configure = { | ||
httpConfiguration = { | ||
requestHeaderSize = 16 * 1024 | ||
} | ||
connector { port = serverPort } | ||
}) { | ||
routing { | ||
get("/") { | ||
call.respond(HttpStatusCode.NoContent) | ||
} | ||
} | ||
}.start(wait = false) | ||
|
||
val create6KBHeaderValue = { List(6 * 1024) { Random.nextInt(33, 127).toChar() }.joinToString("") } | ||
|
||
HttpClient().use { client -> | ||
val response = client.get { | ||
url("http://127.0.0.1:$serverPort/") | ||
header("X-Custom-Large-Header-1", create6KBHeaderValue()) | ||
header("X-Custom-Large-Header-2", create6KBHeaderValue()) | ||
} | ||
assertEquals(HttpStatusCode.NoContent, response.status) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
...erver/ktor-server-jetty/jvm/test/io/ktor/tests/server/jetty/JettyHttpConfigurationTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright 2014-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
package io.ktor.tests.server.jetty | ||
|
||
import io.ktor.client.* | ||
import io.ktor.client.request.* | ||
import io.ktor.http.* | ||
import io.ktor.server.engine.* | ||
import io.ktor.server.jetty.* | ||
import io.ktor.server.response.* | ||
import io.ktor.server.routing.* | ||
import kotlinx.coroutines.test.* | ||
import java.net.* | ||
import kotlin.random.* | ||
import kotlin.test.* | ||
|
||
class JettyHttpConfigurationTest { | ||
|
||
private fun findFreePort() = ServerSocket(0).use { it.localPort } | ||
|
||
@Test | ||
fun `test HttpConfiguration with request header size example`() = runTest { | ||
val serverPort = findFreePort() | ||
|
||
embeddedServer(Jetty, configure = { | ||
httpConfiguration = { | ||
requestHeaderSize = 16 * 1024 | ||
} | ||
connector { port = serverPort } | ||
}) { | ||
routing { | ||
get("/") { | ||
call.respond(HttpStatusCode.NoContent) | ||
} | ||
} | ||
}.start(wait = false) | ||
|
||
val create6KBHeaderValue = { List(6 * 1024) { Random.nextInt(33, 127).toChar() }.joinToString("") } | ||
|
||
HttpClient().use { client -> | ||
val response = client.get { | ||
url("http://127.0.0.1:$serverPort/") | ||
header("X-Custom-Large-Header-1", create6KBHeaderValue()) | ||
header("X-Custom-Large-Header-2", create6KBHeaderValue()) | ||
} | ||
assertEquals(HttpStatusCode.NoContent, response.status) | ||
} | ||
} | ||
} |