Skip to content

Commit

Permalink
Merge branch 'main' into bjhham/file-write-channel-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
bjhham committed Nov 25, 2024
2 parents 1faf7b6 + db760a2 commit 18aeee9
Show file tree
Hide file tree
Showing 47 changed files with 267 additions and 315 deletions.
9 changes: 6 additions & 3 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@ indent_size = 2

[*.{kt,kts}]
ij_kotlin_code_style_defaults = KOTLIN_OFFICIAL
ij_kotlin_name_count_to_use_star_import = 1
ij_kotlin_name_count_to_use_star_import_for_members = 1
ij_kotlin_packages_to_use_import_on_demand = java.util.*, io.ktor.**

ktlint_standard_no-wildcard-imports = disabled
ktlint_standard_trailing-comma-on-call-site = disabled
ktlint_standard_trailing-comma-on-declaration-site = disabled
ktlint_standard_filename = disabled
ktlint_standard_class-naming = disabled
ktlint_standard_annotation = disabled
ktlint_standard_comment-wrapping = disabled
ktlint_standard_comment-wrapping = disabled

[*.kts]
# Always use wildcard imports in scripts
ij_kotlin_name_count_to_use_star_import = 2
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ build
.gradle
.gradletasknamecache
.idea/*
!.idea/externalDependencies.xml
!.idea/runConfigurations
!.idea/runConfigurations/*
!.idea/vcs.xml
Expand Down
6 changes: 6 additions & 0 deletions .idea/externalDependencies.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,21 @@
* Ktor client for Kotlin/Wasm ([KTOR-5587](https://youtrack.jetbrains.com/issue/KTOR-5587))
* CSRF protection feature ([KTOR-2910](https://youtrack.jetbrains.com/issue/KTOR-2910))


# 2.3.13
> Published 20 November 2024
### Bugfixes
* CIO: Requests face connection timeouts when executed on the Android main dispatcher ([KTOR-6803](https://youtrack.jetbrains.com/issue/KTOR-6803))
* io.ktor.util.TextKt.chomp doesn't work on strings with more than one character ([KTOR-7209](https://youtrack.jetbrains.com/issue/KTOR-7209))
* "java.lang.IllegalArgumentException: Failed requirement." in SelectorManagerSupport ([KTOR-2914](https://youtrack.jetbrains.com/issue/KTOR-2914))
* Backport fix for CVE-2024-49580 to Ktor 2 ([KTOR-7727](https://youtrack.jetbrains.com/issue/KTOR-7727))

### Improvements
* Replace custom withTimeout implementation using WeakTimeoutQueue with coroutines.withTimeout ([KTOR-3658](https://youtrack.jetbrains.com/issue/KTOR-3658))
* Add watchosDeviceArm64 target ([KTOR-6368](https://youtrack.jetbrains.com/issue/KTOR-6368))


# 2.3.12
> Published 20 June 2024
Expand Down
9 changes: 5 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,14 @@ A few things to remember:

* Your code should conform to
the official [Kotlin code style guide](https://kotlinlang.org/docs/reference/coding-conventions.html)
except that star imports should be always enabled
(ensure Preferences | Editor | Code Style | Kotlin, tab **Imports**, both `Use import with '*'` should be checked).
except that star imports should always be used for `io.ktor.*` packages.
Code style is managed by [EditorConfig](https://www.jetbrains.com/help/idea/editorconfig.html),
so make sure the EditorConfig plugin is enabled in the IDE.
* Every new source file should have a copyright header.
* Every public API (including functions, classes, objects and so on) should be documented,
every parameter, property, return types and exceptions should be described properly.
* A questionable and new API should be marked with the `@KtorExperimentalAPI` annotation.
* A Public API that is not intended to be used by end-users that couldn't be made private/internal due to technical reasons,
* A Public API which is not intended to be used by end-users that couldn't be made private/internal due to technical
reasons,
should be marked with `@InternalAPI` annotation.

### Commit messages
Expand Down
1 change: 1 addition & 0 deletions buildSrc/settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pluginManagement {
}

plugins {
id("org.gradle.toolchains.foojay-resolver-convention")
id("conventions-dependency-resolution-management")
}

Expand Down
38 changes: 27 additions & 11 deletions buildSrc/src/main/kotlin/JvmConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import org.gradle.kotlin.dsl.*
import org.jetbrains.kotlin.gradle.targets.jvm.tasks.*

fun Project.configureJvm() {
val jdk = when (name) {
val compileJdk = when (name) {
in jdk11Modules -> 11
else -> 8
}
Expand Down Expand Up @@ -56,7 +56,7 @@ fun Project.configureJvm() {
maxHeapSize = "2g"
exclude("**/*StressTest*")
useJUnitPlatform()
configureJavaLauncher(jdk)
configureJavaToolchain(compileJdk)
}

tasks.register<Test>("stressTest") {
Expand All @@ -69,7 +69,7 @@ fun Project.configureJvm() {
systemProperty("enable.stress.tests", "true")
include("**/*StressTest*")
useJUnitPlatform()
configureJavaLauncher(jdk)
configureJavaToolchain(compileJdk)
}

val configuredVersion: String by rootProject.extra
Expand All @@ -86,15 +86,31 @@ fun Project.configureJvm() {
}

/**
* JUnit 5 requires Java 11+
* On local machine use for tests the JDK used for compilation.
* On CI use the default JDK.
*/
fun Test.configureJavaLauncher(jdk: Int) {
if (jdk < 11) {
val javaToolchains = project.extensions.getByType<JavaToolchainService>()
val customLauncher = javaToolchains.launcherFor {
languageVersion = JavaLanguageVersion.of("11")
}
javaLauncher = customLauncher
private fun Test.configureJavaToolchain(compileJdk: Int) {
// JUnit 5 requires JDK 11+
val testJdk = (if (CI) currentJdk else compileJdk).coerceAtLeast(11)
val javaToolchains = project.the<JavaToolchainService>()

javaLauncher = javaToolchains.launcherFor {
languageVersion = JavaLanguageVersion.of(testJdk)
}

if (testJdk >= 16) {
// Allow reflective access from tests
jvmArgs(
"--add-opens=java.base/java.net=ALL-UNNAMED",
"--add-opens=java.base/java.time=ALL-UNNAMED",
"--add-opens=java.base/java.util=ALL-UNNAMED",
)
}

if (testJdk >= 21) {
// coroutines-debug use dynamic agent loading under the hood.
// Remove as soon as the issue is fixed: https://youtrack.jetbrains.com/issue/KT-62096/
jvmArgs("-XX:+EnableDynamicAgentLoading")
}
}

Expand Down
28 changes: 1 addition & 27 deletions buildSrc/src/main/kotlin/KtorBuildProperties.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,6 @@
*/

import org.gradle.api.*
import org.gradle.api.tasks.testing.*
import org.gradle.jvm.toolchain.*
import org.gradle.kotlin.dsl.*

/*
* Copyright 2014-2021 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

private val java_version: String = System.getProperty("java.version", "8.0.0")

private val versionComponents = java_version
.split(".")
.take(2)
.filter { it.isNotBlank() }
.map { Integer.parseInt(it) }

val IDEA_ACTIVE: Boolean = System.getProperty("idea.active") == "true"

Expand All @@ -30,7 +15,7 @@ val HOST_NAME = when {
else -> error("Unknown os name `$OS_NAME`")
}

val currentJdk = if (versionComponents[0] == 1) versionComponents[1] else versionComponents[0]
val currentJdk = JavaVersion.current().majorVersion.toInt()

val jdk11Modules = listOf(
"ktor-client-java",
Expand All @@ -40,14 +25,3 @@ val jdk11Modules = listOf(
"ktor-server-jetty-test-http2-jakarta",
"ktor-server-tomcat-jakarta",
)

fun Project.useJdkVersionForJvmTests(version: Int) {
tasks.named<Test>("jvmTest") {
val javaToolchains = project.extensions.getByType<JavaToolchainService>()
javaLauncher.set(
javaToolchains.launcherFor {
languageVersion.set(JavaLanguageVersion.of(version))
}
)
}
}
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jetty-alpn-boot = "8.1.13.v20181017"
jetty-alpn-openjdk8 = "9.4.56.v20240826"

tomcat = "9.0.97"
tomcat-jakarta = "10.1.31"
tomcat-jakarta = "10.1.33"

apache = "4.1.5"
apache5 = "5.3.1"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014-2019 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
* 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.client.engine.cio
Expand All @@ -11,26 +11,26 @@ import io.ktor.client.plugins.*
import io.ktor.client.request.*
import io.ktor.client.statement.*
import io.ktor.http.*
import io.ktor.junit.*
import io.ktor.network.tls.certificates.*
import io.ktor.server.application.*
import io.ktor.server.engine.*
import io.ktor.server.netty.*
import io.ktor.server.response.*
import io.ktor.server.routing.*
import io.ktor.utils.io.*
import kotlinx.coroutines.*
import kotlinx.coroutines.debug.junit5.*
import org.junit.jupiter.api.extension.*
import java.io.*
import java.net.*
import java.util.concurrent.*
import javax.net.ssl.*
import kotlin.concurrent.*
import kotlinx.coroutines.debug.junit5.CoroutinesTimeout
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withTimeout
import java.io.File
import java.net.ConnectException
import java.net.ServerSocket
import java.net.SocketException
import java.util.concurrent.TimeUnit
import javax.net.ssl.TrustManagerFactory
import javax.net.ssl.X509TrustManager
import kotlin.concurrent.thread
import kotlin.test.*

@CoroutinesTimeout(5 * 60 * 1000)
@ExtendWith(RetrySupport::class)
class ConnectErrorsTest {

private val serverSocket = ServerSocket(0, 1)
Expand All @@ -40,7 +40,7 @@ class ConnectErrorsTest {
serverSocket.close()
}

@RetryableTest(3)
@Test
fun testConnectAfterConnectionErrors(): Unit = runBlocking {
val client = HttpClient(CIO) {
engine {
Expand Down Expand Up @@ -84,7 +84,7 @@ class ConnectErrorsTest {
}
}

@RetryableTest(3)
@Test
fun testResponseWithNoLengthChunkedAndConnectionClosedWithHttp10(): Unit = runBlocking {
val client = HttpClient(CIO)

Expand All @@ -110,7 +110,7 @@ class ConnectErrorsTest {
}
}

@RetryableTest(3)
@Test
fun testResponseErrorWithNoLengthChunkedAndConnectionClosedWithHttp11(): Unit = runBlocking {
val client = HttpClient(CIO)

Expand Down Expand Up @@ -183,7 +183,7 @@ class ConnectErrorsTest {
}
}

@RetryableTest(3)
@Test
fun testLateServerStart(): Unit = runBlocking {
val keyStoreFile = File("build/temp.jks")
val keyStore = generateCertificate(keyStoreFile, algorithm = "SHA256withECDSA", keySizeInBits = 256)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import test.server.*

/*
* Copyright 2014-2021 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/
* Copyright 2014-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

import test.server.*

description = "Ktor client Auth support"

apply<TestServerPlugin>()

useJdkVersionForJvmTests(11)
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/*
* Copyright 2014-2020 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
* Copyright 2014-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

description = "Ktor client Byte Order Mark support"

useJdkVersionForJvmTests(11)
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
/*
* Copyright 2014-2021 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
* Copyright 2014-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

useJdkVersionForJvmTests(11)

apply<test.server.TestServerPlugin>()

kotlin.sourceSets {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright 2014-2021 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/
* Copyright 2014-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

description = "Ktor client JSON support"

Expand Down Expand Up @@ -29,5 +29,3 @@ kotlin {
}
}
}

useJdkVersionForJvmTests(11)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright 2014-2021 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/
* Copyright 2014-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

kotlin.sourceSets {
commonTest {
Expand All @@ -9,5 +9,3 @@ kotlin.sourceSets {
}
}
}

useJdkVersionForJvmTests(11)
8 changes: 0 additions & 8 deletions ktor-client/ktor-client-tests/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@

import test.server.*

/*
* Copyright 2014-2021 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

description = "Common tests for client"

plugins {
Expand All @@ -16,8 +12,6 @@ plugins {

apply<TestServerPlugin>()

val osName = System.getProperty("os.name")

kotlin.sourceSets {
commonMain {
dependencies {
Expand Down Expand Up @@ -105,5 +99,3 @@ kotlin.sourceSets {
}
}
}

useJdkVersionForJvmTests(11)
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ expect abstract class ClientLoader(timeoutSeconds: Int = 60) {
fun clientTests(
skipEngines: List<String> = emptyList(),
onlyWithEngine: String? = null,
retries: Int = 1,
block: suspend TestClientBuilder<HttpClientEngineConfig>.() -> Unit
): TestResult

Expand Down
Loading

0 comments on commit 18aeee9

Please sign in to comment.