From 4c5a2f6f320c8acf360859dbb68d60141d3f4ed7 Mon Sep 17 00:00:00 2001 From: Leonid Stashevsky Date: Fri, 21 May 2021 13:46:50 +0300 Subject: [PATCH] Fix rebase issues --- .idea/codeStyles/Project.xml | 20 +-- gradle.properties | 2 +- .../src/io/ktor/client/call/SavedCall.kt | 3 +- .../io/ktor/client/engine/mock/MockEngine.kt | 4 +- .../io/ktor/client/plugins/auth/AuthTest.kt | 18 +- .../features/tracing/StethoTracerTest.kt | 2 +- .../ktor-client-tests/build.gradle.kts | 2 +- .../test/io/ktor/client/tests/CharsetTest.kt | 5 +- .../test/io/ktor/client/tests/HeadersTest.kt | 8 +- .../io/ktor/client/tests/HttpRedirectTest.kt | 4 +- .../test/io/ktor/client/tests/LoggingTest.kt | 8 +- .../test/io/ktor/client/tests/UploadTest.kt | 1 + .../client/tests/utils/ClientTestServer.kt | 2 +- .../client/tests/utils/tests/WebSockets.kt | 1 + .../io/ktor/client/tests/WebSocketJvmTest.kt | 5 +- .../tests/InvalidMutabilityExceptionTest.kt | 4 +- .../ktor/utils/io/core/BytePacketBuilder.kt | 10 -- .../io/ktor/utils/io/charsets/CharsetJS.kt | 8 +- .../.gitkeep => ktor-legacy/jvm/.gitignore | 0 .../jvm/src/io/ktor/network/tls/Headers.kt | 1 - .../io/ktor/network/tls/TLSClientHandshake.kt | 7 +- .../api/ktor-server-double-receive.api | 34 ---- ktor-server/ktor-server-core/js/.gitkeep | 0 ktor-server/ktor-server-core/posix/.gitkeep | 0 .../server/engine/BaseApplicationEngine.kt | 4 +- ...licationEngineEnvironmentReloadingTests.kt | 8 +- .../ktor/server/netty/NettyApplicationCall.kt | 5 + .../netty/NettyApplicationCallHandler.kt | 1 + .../server/netty/NettyApplicationRequest.kt | 2 - .../netty/NettyApplicationRequestHeaders.kt | 2 - .../server/netty/NettyApplicationResponse.kt | 26 +-- .../http1/NettyHttp1ApplicationRequest.kt | 1 - .../http1/NettyHttp1ApplicationResponse.kt | 2 - .../io/ktor/server/plugins/DoubleReceive.kt | 3 +- .../test/io/ktor/tests/servlet/HoconTest.kt | 2 +- .../testing/suites/ConnectionTestSuite.kt | 3 +- .../testing/suites/HttpServerTestSuite.kt | 3 +- .../testing/suites/SustainabilityTestSuite.kt | 2 +- .../tests/server/tomcat/TomcatEngineTest.kt | 2 + .../jvm/test-resources/error404.html | 1 - .../jvm/test-resources/logback-test.xml | 18 -- .../jvm/test-resources/testjar.jar | Bin 559 -> 0 bytes .../test/io/ktor/tests/config/ConfigTest.kt | 140 --------------- .../tests/http/FindContainingJarFileTest.kt | 29 --- .../test/io/ktor/tests/http/ParametersTest.kt | 54 ------ .../ktor/tests/http/PathNormalizationTest.kt | 142 --------------- .../content/StaticContentResolutionTest.kt | 42 ----- .../ktor/tests/routing/RouteSelectorTest.kt | 166 ------------------ .../test/io/ktor/tests/routing/RouteTest.kt | 32 ---- .../tests/utils/CopyOnWriteHashMapTest.kt | 99 ----------- .../test/io/ktor/tests/utils/DateJvmTest.kt | 60 ------- ktor-shared/build.gradle | 9 - ktor-shared/build.gradle.kts | 11 ++ ktor-shared/common/.gitkeep | 0 ktor-shared/js/.gitkeep | 0 ktor-shared/posix/.gitkeep | 0 56 files changed, 99 insertions(+), 919 deletions(-) rename ktor-server/ktor-server-core/common/.gitkeep => ktor-legacy/jvm/.gitignore (100%) delete mode 100644 ktor-server-features/ktor-server-double-receive/api/ktor-server-double-receive.api delete mode 100644 ktor-server/ktor-server-core/js/.gitkeep delete mode 100644 ktor-server/ktor-server-core/posix/.gitkeep delete mode 100644 ktor-server/ktor-server/jvm/test-resources/error404.html delete mode 100644 ktor-server/ktor-server/jvm/test-resources/logback-test.xml delete mode 100644 ktor-server/ktor-server/jvm/test-resources/testjar.jar delete mode 100644 ktor-server/ktor-server/jvm/test/io/ktor/tests/config/ConfigTest.kt delete mode 100644 ktor-server/ktor-server/jvm/test/io/ktor/tests/http/FindContainingJarFileTest.kt delete mode 100644 ktor-server/ktor-server/jvm/test/io/ktor/tests/http/ParametersTest.kt delete mode 100644 ktor-server/ktor-server/jvm/test/io/ktor/tests/http/PathNormalizationTest.kt delete mode 100644 ktor-server/ktor-server/jvm/test/io/ktor/tests/http/content/StaticContentResolutionTest.kt delete mode 100644 ktor-server/ktor-server/jvm/test/io/ktor/tests/routing/RouteSelectorTest.kt delete mode 100644 ktor-server/ktor-server/jvm/test/io/ktor/tests/routing/RouteTest.kt delete mode 100644 ktor-server/ktor-server/jvm/test/io/ktor/tests/utils/CopyOnWriteHashMapTest.kt delete mode 100644 ktor-server/ktor-server/jvm/test/io/ktor/tests/utils/DateJvmTest.kt delete mode 100644 ktor-shared/build.gradle create mode 100644 ktor-shared/build.gradle.kts delete mode 100644 ktor-shared/common/.gitkeep delete mode 100644 ktor-shared/js/.gitkeep delete mode 100644 ktor-shared/posix/.gitkeep diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml index 24e8abffcfc..d94a29c496a 100644 --- a/.idea/codeStyles/Project.xml +++ b/.idea/codeStyles/Project.xml @@ -1,12 +1,12 @@ - - - - - - + + + + + + diff --git a/gradle.properties b/gradle.properties index 7e7797b007a..5502465ce2f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -48,7 +48,7 @@ nodejs_version=14.17.1 npm_version=6.4.1 slf4j_version=1.7.30 ktlint_version=3.3.0 -mockk_version=1.10.6 +mockk_version=1.12.0 mokito_kotlin_version=1.6.0 # typesafe config couldn't be upgraded due to android restrictions diff --git a/ktor-client/ktor-client-core/common/src/io/ktor/client/call/SavedCall.kt b/ktor-client/ktor-client-core/common/src/io/ktor/client/call/SavedCall.kt index 7d04bb48230..be0093fbe06 100644 --- a/ktor-client/ktor-client-core/common/src/io/ktor/client/call/SavedCall.kt +++ b/ktor-client/ktor-client-core/common/src/io/ktor/client/call/SavedCall.kt @@ -8,9 +8,9 @@ import io.ktor.client.* import io.ktor.client.request.* import io.ktor.client.statement.* import io.ktor.http.* +import io.ktor.util.* import io.ktor.util.date.* import io.ktor.utils.io.* -import io.ktor.utils.io.concurrent.* import io.ktor.utils.io.core.* import kotlinx.coroutines.* import kotlin.coroutines.* @@ -20,7 +20,6 @@ internal class SavedHttpCall(client: HttpClient, private val responseBody: ByteA /** * Returns a channel with [responseBody] data. */ - @OptIn(InternalAPI::class) override suspend fun getResponseContent(): ByteReadChannel { return ByteReadChannel(responseBody) } diff --git a/ktor-client/ktor-client-mock/common/src/io/ktor/client/engine/mock/MockEngine.kt b/ktor-client/ktor-client-mock/common/src/io/ktor/client/engine/mock/MockEngine.kt index 6df8f7949dc..95c119d1ae5 100644 --- a/ktor-client/ktor-client-mock/common/src/io/ktor/client/engine/mock/MockEngine.kt +++ b/ktor-client/ktor-client-mock/common/src/io/ktor/client/engine/mock/MockEngine.kt @@ -6,7 +6,7 @@ package io.ktor.client.engine.mock import io.ktor.client.engine.* import io.ktor.client.plugins.* -import io.ktor.client.features.websocket.* +import io.ktor.client.plugins.websocket.* import io.ktor.client.request.* import io.ktor.client.utils.* import io.ktor.util.* @@ -21,7 +21,7 @@ public class MockEngine(override val config: MockEngineConfig) : HttpClientEngin @OptIn(InternalAPI::class) override val dispatcher: CoroutineDispatcher = Dispatchers.clientDispatcher(config.threadsCount) override val supportedCapabilities: Set> = setOf( - HttpTimeout, + HttpTimeout.Plugin, WebSocketCapability, WebSocketExtensionsCapability ) diff --git a/ktor-client/ktor-client-plugins/ktor-client-auth/common/test/io/ktor/client/plugins/auth/AuthTest.kt b/ktor-client/ktor-client-plugins/ktor-client-auth/common/test/io/ktor/client/plugins/auth/AuthTest.kt index 025e00cc92e..0696bec475e 100644 --- a/ktor-client/ktor-client-plugins/ktor-client-auth/common/test/io/ktor/client/plugins/auth/AuthTest.kt +++ b/ktor-client/ktor-client-plugins/ktor-client-auth/common/test/io/ktor/client/plugins/auth/AuthTest.kt @@ -9,11 +9,11 @@ import io.ktor.client.call.* import io.ktor.client.plugins.* import io.ktor.client.plugins.auth.providers.* import io.ktor.client.request.* -import io.ktor.client.request.get import io.ktor.client.statement.* import io.ktor.client.tests.utils.* import io.ktor.http.* import io.ktor.util.* +import io.ktor.utils.io.concurrent.* import kotlinx.coroutines.* import kotlin.test.* @@ -245,7 +245,7 @@ class AuthTest : ClientLoader() { test { client -> client.get("$TEST_SERVER/auth/basic-fixed") - client.post("$TEST_SERVER/auth/basic").let { + client.post("$TEST_SERVER/auth/basic") { expectSuccess = false }.let { assertEquals(HttpStatusCode.Unauthorized, it.status) } } @@ -344,7 +344,7 @@ class AuthTest : ClientLoader() { test { client -> val response = withContext(Dispatchers.Default) { - client.get("$TEST_SERVER/auth/bearer/test-refresh").execute() + client.get("$TEST_SERVER/auth/bearer/test-refresh") } assertEquals(HttpStatusCode.OK, response.status) } @@ -363,12 +363,12 @@ class AuthTest : ClientLoader() { install(Auth) { bearer { loadTokens { - val token = clientWithAuth!!.get("$TEST_SERVER/auth/bearer/token/first") + val token = clientWithAuth!!.get("$TEST_SERVER/auth/bearer/token/first").bodyAsText() BearerTokens(token, token) } refreshTokens { - val token = clientWithAuth!!.get("$TEST_SERVER/auth/bearer/token/second") + val token = clientWithAuth!!.get("$TEST_SERVER/auth/bearer/token/second").bodyAsText() BearerTokens(token, token) } } @@ -376,7 +376,7 @@ class AuthTest : ClientLoader() { } val first = clientWithAuth!!.get("$TEST_SERVER/auth/bearer/first").bodyAsText() - val second = clientWithAuth!!.get("$TEST_SERVER/auth/bearer/second") + val second = clientWithAuth!!.get("$TEST_SERVER/auth/bearer/second").bodyAsText() assertEquals("OK", first) assertEquals("OK", second) @@ -424,9 +424,11 @@ class AuthTest : ClientLoader() { test { client -> loadCount = 0 - client.get("$TEST_SERVER/auth/bearer/test-refresh") + client.get("$TEST_SERVER/auth/bearer/test-refresh") + .bodyAsText() client[Auth].providers.filterIsInstance().first().clearToken() - client.get("$TEST_SERVER/auth/bearer/test-refresh") + client.get("$TEST_SERVER/auth/bearer/test-refresh") + .bodyAsText() assertEquals(2, loadCount) } diff --git a/ktor-client/ktor-client-plugins/ktor-client-tracing/ktor-client-tracing-stetho/android/test/io/ktor/client/features/tracing/StethoTracerTest.kt b/ktor-client/ktor-client-plugins/ktor-client-tracing/ktor-client-tracing-stetho/android/test/io/ktor/client/features/tracing/StethoTracerTest.kt index fc0f85b1bc2..28fea9fd5da 100644 --- a/ktor-client/ktor-client-plugins/ktor-client-tracing/ktor-client-tracing-stetho/android/test/io/ktor/client/features/tracing/StethoTracerTest.kt +++ b/ktor-client/ktor-client-plugins/ktor-client-tracing/ktor-client-tracing-stetho/android/test/io/ktor/client/features/tracing/StethoTracerTest.kt @@ -20,7 +20,7 @@ class StethoTracerTest { val activity = createTestAndroidActivity() with(activity) { val client = HttpClient(Stetho(CIO)) - val page = runBlocking { client.get("http://www.google.com") } + val page = runBlocking { client.get("http://www.google.com").bodyAsText() } assertNotNull(page) } } diff --git a/ktor-client/ktor-client-tests/build.gradle.kts b/ktor-client/ktor-client-tests/build.gradle.kts index a1694bda351..f3794c663ca 100644 --- a/ktor-client/ktor-client-tests/build.gradle.kts +++ b/ktor-client/ktor-client-tests/build.gradle.kts @@ -180,7 +180,7 @@ rootProject.allprojects { if (!(rootProject.ext.get("native_targets_enabled") as Boolean)) { return@sourceSets } - if (ideaActive) { + if (KtorBuildProperties.ideaActive) { if (name == "posixTest") { getByName(name) { dependencies { diff --git a/ktor-client/ktor-client-tests/common/test/io/ktor/client/tests/CharsetTest.kt b/ktor-client/ktor-client-tests/common/test/io/ktor/client/tests/CharsetTest.kt index e56058c7ddd..7382292de2c 100644 --- a/ktor-client/ktor-client-tests/common/test/io/ktor/client/tests/CharsetTest.kt +++ b/ktor-client/ktor-client-tests/common/test/io/ktor/client/tests/CharsetTest.kt @@ -8,6 +8,7 @@ import io.ktor.client.call.* import io.ktor.client.engine.mock.* import io.ktor.client.plugins.* import io.ktor.client.request.* +import io.ktor.client.statement.* import io.ktor.client.tests.utils.* import io.ktor.client.utils.* import io.ktor.http.* @@ -203,7 +204,7 @@ class CharsetTest { } test { client -> - val response = client.get() + val response = client.get { }.bodyAsText() assertEquals("Content", response) } } @@ -231,7 +232,7 @@ class CharsetTest { } test { client -> - val response = client.get() + val response = client.get { }.bodyAsText() assertEquals("Content", response) } } diff --git a/ktor-client/ktor-client-tests/common/test/io/ktor/client/tests/HeadersTest.kt b/ktor-client/ktor-client-tests/common/test/io/ktor/client/tests/HeadersTest.kt index ab2500e16e1..d522d901eca 100644 --- a/ktor-client/ktor-client-tests/common/test/io/ktor/client/tests/HeadersTest.kt +++ b/ktor-client/ktor-client-tests/common/test/io/ktor/client/tests/HeadersTest.kt @@ -95,16 +95,16 @@ class HeadersTest : ClientLoader() { @Test fun testRequestHasContentLength() = clientTests(listOf("Java", "Curl", "Js")) { test { client -> - val get = client.get("$TEST_SERVER/headers") + val get = client.get("$TEST_SERVER/headers").bodyAsText() assertEquals("", get) - val head = client.head("$TEST_SERVER/headers") + val head = client.head("$TEST_SERVER/headers").bodyAsText() assertEquals("", head) - val put = client.put("$TEST_SERVER/headers") + val put = client.put("$TEST_SERVER/headers").bodyAsText() assertEquals("0", put) - val post = client.post("$TEST_SERVER/headers") + val post = client.post("$TEST_SERVER/headers").bodyAsText() assertEquals("0", post) } } diff --git a/ktor-client/ktor-client-tests/common/test/io/ktor/client/tests/HttpRedirectTest.kt b/ktor-client/ktor-client-tests/common/test/io/ktor/client/tests/HttpRedirectTest.kt index e688c633fc0..e2a1611f551 100644 --- a/ktor-client/ktor-client-tests/common/test/io/ktor/client/tests/HttpRedirectTest.kt +++ b/ktor-client/ktor-client-tests/common/test/io/ktor/client/tests/HttpRedirectTest.kt @@ -37,9 +37,9 @@ class HttpRedirectTest : ClientLoader() { } test { client -> - client.get("$TEST_URL_BASE/encodedQuery").execute { + client.prepareGet("$TEST_URL_BASE/encodedQuery").execute { assertEquals(HttpStatusCode.OK, it.status) - assertEquals("/redirect/getWithUri?key=value1%3Bvalue2%3D%22some=thing", it.readText()) + assertEquals("/redirect/getWithUri?key=value1%3Bvalue2%3D%22some=thing", it.bodyAsText()) } } } diff --git a/ktor-client/ktor-client-tests/common/test/io/ktor/client/tests/LoggingTest.kt b/ktor-client/ktor-client-tests/common/test/io/ktor/client/tests/LoggingTest.kt index 268621e6b93..19d68790aeb 100644 --- a/ktor-client/ktor-client-tests/common/test/io/ktor/client/tests/LoggingTest.kt +++ b/ktor-client/ktor-client-tests/common/test/io/ktor/client/tests/LoggingTest.kt @@ -467,10 +467,10 @@ class LoggingTest : ClientLoader() { } test { client -> - val response = client.request { + val response = client.prepareGet { method = HttpMethod.Get url("$TEST_SERVER/compression/deflate") - }.receive() + }.body() assertEquals("Compressed response!", response) } after { @@ -495,11 +495,11 @@ class LoggingTest : ClientLoader() { body.close() } - val response = client.request { + val response = client.prepareRequest { method = HttpMethod.Post url("$TEST_SERVER/content/echo") setBody(body) - }.receive() + }.body() response.discard() } } diff --git a/ktor-client/ktor-client-tests/common/test/io/ktor/client/tests/UploadTest.kt b/ktor-client/ktor-client-tests/common/test/io/ktor/client/tests/UploadTest.kt index 94b76f0159d..565e0c96166 100644 --- a/ktor-client/ktor-client-tests/common/test/io/ktor/client/tests/UploadTest.kt +++ b/ktor-client/ktor-client-tests/common/test/io/ktor/client/tests/UploadTest.kt @@ -4,6 +4,7 @@ package io.ktor.client.tests +import io.ktor.client.call.* import io.ktor.client.request.* import io.ktor.client.tests.utils.* import io.ktor.content.* diff --git a/ktor-client/ktor-client-tests/jvm/src/io/ktor/client/tests/utils/ClientTestServer.kt b/ktor-client/ktor-client-tests/jvm/src/io/ktor/client/tests/utils/ClientTestServer.kt index 61dbdac208f..441ec4b191a 100644 --- a/ktor-client/ktor-client-tests/jvm/src/io/ktor/client/tests/utils/ClientTestServer.kt +++ b/ktor-client/ktor-client-tests/jvm/src/io/ktor/client/tests/utils/ClientTestServer.kt @@ -15,7 +15,7 @@ import io.ktor.server.routing.* internal fun Application.tests() { install(io.ktor.server.websocket.WebSockets) { - maxFrameSize = 4 * 1024 + maxFrameSize = 4 * 1024L extensions { install(WebSocketDeflateExtension) diff --git a/ktor-client/ktor-client-tests/jvm/src/io/ktor/client/tests/utils/tests/WebSockets.kt b/ktor-client/ktor-client-tests/jvm/src/io/ktor/client/tests/utils/tests/WebSockets.kt index c28f1043d6c..d7c1f5671f5 100644 --- a/ktor-client/ktor-client-tests/jvm/src/io/ktor/client/tests/utils/tests/WebSockets.kt +++ b/ktor-client/ktor-client-tests/jvm/src/io/ktor/client/tests/utils/tests/WebSockets.kt @@ -26,6 +26,7 @@ internal fun Application.webSockets() { webSocket("headers") { val headers = call.request.headers.toMap() + @OptIn(ExperimentalSerializationApi::class) val headersJson = Json.encodeToString(headers) send(Frame.Text(headersJson)) } diff --git a/ktor-client/ktor-client-tests/jvm/test/io/ktor/client/tests/WebSocketJvmTest.kt b/ktor-client/ktor-client-tests/jvm/test/io/ktor/client/tests/WebSocketJvmTest.kt index 02acc90f604..5d67f5d30da 100644 --- a/ktor-client/ktor-client-tests/jvm/test/io/ktor/client/tests/WebSocketJvmTest.kt +++ b/ktor-client/ktor-client-tests/jvm/test/io/ktor/client/tests/WebSocketJvmTest.kt @@ -5,7 +5,6 @@ package io.ktor.client.tests import io.ktor.client.plugins.websocket.* -import io.ktor.client.tests.features.* import io.ktor.client.tests.utils.* import io.ktor.http.cio.websocket.* import kotlin.test.* @@ -15,7 +14,7 @@ private const val TEST_SIZE: Int = 100 class WebSocketJvmTest : ClientLoader(100000) { @Test - fun testWebSocketDeflateBinary() = clientTests(ENGINES_WITHOUT_WS_EXTENSIONS) { + fun testWebSocketDeflateBinary() = clientTests(listOf("Android", "Apache")) { config { WebSockets { extensions { @@ -39,7 +38,7 @@ class WebSocketJvmTest : ClientLoader(100000) { } @Test - fun testWebSocketDeflateNoContextTakeover() = clientTests(ENGINES_WITHOUT_WS_EXTENSIONS) { + fun testWebSocketDeflateNoContextTakeover() = clientTests(listOf("Android", "Apache")) { config { WebSockets { extensions { diff --git a/ktor-client/ktor-client-tests/posix/test/io/ktor/client/tests/InvalidMutabilityExceptionTest.kt b/ktor-client/ktor-client-tests/posix/test/io/ktor/client/tests/InvalidMutabilityExceptionTest.kt index 7f1bb74fba3..f11181a3827 100644 --- a/ktor-client/ktor-client-tests/posix/test/io/ktor/client/tests/InvalidMutabilityExceptionTest.kt +++ b/ktor-client/ktor-client-tests/posix/test/io/ktor/client/tests/InvalidMutabilityExceptionTest.kt @@ -17,9 +17,9 @@ class InvalidMutabilityExceptionTest : ClientLoader() { test { client -> val cause = assertFails { val response = withContext(Dispatchers.Default) { - client.get("$TEST_SERVER/content/hello") + client.get("$TEST_SERVER/content/hello") } - response.readText() + response.bodyAsText() } assertIs(cause) diff --git a/ktor-io/common/src/io/ktor/utils/io/core/BytePacketBuilder.kt b/ktor-io/common/src/io/ktor/utils/io/core/BytePacketBuilder.kt index 13dd537aec9..486f0122f9b 100644 --- a/ktor-io/common/src/io/ktor/utils/io/core/BytePacketBuilder.kt +++ b/ktor-io/common/src/io/ktor/utils/io/core/BytePacketBuilder.kt @@ -5,16 +5,6 @@ package io.ktor.utils.io.core import io.ktor.utils.io.bits.* import io.ktor.utils.io.core.internal.* import io.ktor.utils.io.pool.* -import kotlin.Boolean -import kotlin.Char -import kotlin.CharSequence -import kotlin.Deprecated -import kotlin.DeprecationLevel -import kotlin.Int -import kotlin.PublishedApi -import kotlin.String -import kotlin.Suppress -import kotlin.jvm.* /** * A builder that provides ability to build byte packets with no knowledge of it's size. diff --git a/ktor-io/js/src/io/ktor/utils/io/charsets/CharsetJS.kt b/ktor-io/js/src/io/ktor/utils/io/charsets/CharsetJS.kt index 7301f42fd91..5c4df4e3c55 100644 --- a/ktor-io/js/src/io/ktor/utils/io/charsets/CharsetJS.kt +++ b/ktor-io/js/src/io/ktor/utils/io/charsets/CharsetJS.kt @@ -12,16 +12,14 @@ public actual abstract class Charset(internal val _name: String) { @Suppress("LocalVariableName") public actual fun forName(name: String): Charset { if (name == "UTF-8" || name == "utf-8" || name == "UTF8" || name == "utf8") return Charsets.UTF_8 - if (name == "ISO-8859-1" || name == "iso-8859-1" || - name.replace('_', '-').let { it == "iso-8859-1" || it.toLowerCase() == "iso-8859-1" } || - name == "latin1" || name == "Latin1" + if (name == "ISO-8859-1" || name == "iso-8859-1" + || name.replace('_', '-').let { it == "iso-8859-1" || it.toLowerCase() == "iso-8859-1" } + || name == "latin1" || name == "Latin1" ) { return Charsets.ISO_8859_1 } throw IllegalArgumentException("Charset $name is not supported") } - } -} public actual fun isSupported(charset: String): Boolean = when { charset == "UTF-8" || charset == "utf-8" || charset == "UTF8" || charset == "utf8" -> true diff --git a/ktor-server/ktor-server-core/common/.gitkeep b/ktor-legacy/jvm/.gitignore similarity index 100% rename from ktor-server/ktor-server-core/common/.gitkeep rename to ktor-legacy/jvm/.gitignore diff --git a/ktor-network/ktor-network-tls/jvm/src/io/ktor/network/tls/Headers.kt b/ktor-network/ktor-network-tls/jvm/src/io/ktor/network/tls/Headers.kt index bd791c32ece..320cd5365db 100644 --- a/ktor-network/ktor-network-tls/jvm/src/io/ktor/network/tls/Headers.kt +++ b/ktor-network/ktor-network-tls/jvm/src/io/ktor/network/tls/Headers.kt @@ -4,7 +4,6 @@ package io.ktor.network.tls -import io.ktor.util.* import io.ktor.utils.io.core.* @Suppress("KDocMissingDocumentation") diff --git a/ktor-network/ktor-network-tls/jvm/src/io/ktor/network/tls/TLSClientHandshake.kt b/ktor-network/ktor-network-tls/jvm/src/io/ktor/network/tls/TLSClientHandshake.kt index 84f49c6e9f9..9cf764457eb 100644 --- a/ktor-network/ktor-network-tls/jvm/src/io/ktor/network/tls/TLSClientHandshake.kt +++ b/ktor-network/ktor-network-tls/jvm/src/io/ktor/network/tls/TLSClientHandshake.kt @@ -156,7 +156,7 @@ internal class TLSClientHandshake( } } - public suspend fun negotiate() { + suspend fun negotiate() { digest.use { sendClientHello() serverHello = receiveServerHello() @@ -377,8 +377,9 @@ internal class TLSClientHandshake( if (hasHashAndSignInCommon) return@find false - info.authorities.isEmpty() || - candidate.certificateChain.map { X500Principal(it.issuerDN.name) }.any { it in info.authorities } + info.authorities.isEmpty() || candidate.certificateChain + .map { X500Principal(it.issuerX500Principal.name) } + .any { it in info.authorities } } sendHandshakeRecord(TLSHandshakeType.Certificate) { diff --git a/ktor-server-features/ktor-server-double-receive/api/ktor-server-double-receive.api b/ktor-server-features/ktor-server-double-receive/api/ktor-server-double-receive.api deleted file mode 100644 index 38197296090..00000000000 --- a/ktor-server-features/ktor-server-double-receive/api/ktor-server-double-receive.api +++ /dev/null @@ -1,34 +0,0 @@ -public abstract class io/ktor/server/features/CachedTransformationResult { - public synthetic fun (Lkotlin/reflect/KType;Lkotlin/jvm/internal/DefaultConstructorMarker;)V - public final fun getType ()Lkotlin/reflect/KType; -} - -public class io/ktor/server/features/CachedTransformationResult$Failure : io/ktor/server/features/CachedTransformationResult { - public fun (Lkotlin/reflect/KType;Ljava/lang/Throwable;)V - public final fun getCause ()Ljava/lang/Throwable; -} - -public final class io/ktor/server/features/CachedTransformationResult$Success : io/ktor/server/features/CachedTransformationResult { - public fun (Lkotlin/reflect/KType;Ljava/lang/Object;)V - public final fun getValue ()Ljava/lang/Object; -} - -public final class io/ktor/server/features/DoubleReceive { - public static final field Feature Lio/ktor/server/features/DoubleReceive$Feature; -} - -public final class io/ktor/server/features/DoubleReceive$Configuration { - public fun ()V - public final fun getReceiveEntireContent ()Z - public final fun setReceiveEntireContent (Z)V -} - -public final class io/ktor/server/features/DoubleReceive$Feature : io/ktor/server/application/ApplicationFeature { - public fun getKey ()Lio/ktor/util/AttributeKey; - public fun install (Lio/ktor/server/application/Application;Lkotlin/jvm/functions/Function1;)Lio/ktor/server/features/DoubleReceive; - public synthetic fun install (Lio/ktor/util/pipeline/Pipeline;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; -} - -public final class io/ktor/server/features/RequestReceiveAlreadyFailedException : java/lang/Exception { -} - diff --git a/ktor-server/ktor-server-core/js/.gitkeep b/ktor-server/ktor-server-core/js/.gitkeep deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/ktor-server/ktor-server-core/posix/.gitkeep b/ktor-server/ktor-server-core/posix/.gitkeep deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/ktor-server/ktor-server-host-common/jvm/src/io/ktor/server/engine/BaseApplicationEngine.kt b/ktor-server/ktor-server-host-common/jvm/src/io/ktor/server/engine/BaseApplicationEngine.kt index e9419fbc2c7..cd29b3fe0a4 100644 --- a/ktor-server/ktor-server-host-common/jvm/src/io/ktor/server/engine/BaseApplicationEngine.kt +++ b/ktor-server/ktor-server-host-common/jvm/src/io/ktor/server/engine/BaseApplicationEngine.kt @@ -79,7 +79,9 @@ public abstract class BaseApplicationEngine( if (isResponded) { return@intercept } - val status = call.response.status() ?: HttpStatusCode.NotFound + val status = call.response.status() + ?: call.attributes.getOrNull(RoutingFailureStatusCode) + ?: HttpStatusCode.NotFound call.respond(status) } diff --git a/ktor-server/ktor-server-host-common/jvm/test/io/ktor/tests/hosts/ApplicationEngineEnvironmentReloadingTests.kt b/ktor-server/ktor-server-host-common/jvm/test/io/ktor/tests/hosts/ApplicationEngineEnvironmentReloadingTests.kt index b0d86b9ab8a..fc0276e58e5 100644 --- a/ktor-server/ktor-server-host-common/jvm/test/io/ktor/tests/hosts/ApplicationEngineEnvironmentReloadingTests.kt +++ b/ktor-server/ktor-server-host-common/jvm/test/io/ktor/tests/hosts/ApplicationEngineEnvironmentReloadingTests.kt @@ -7,12 +7,12 @@ package io.ktor.tests.hosts import com.typesafe.config.* +import io.ktor.http.* import io.ktor.server.application.* import io.ktor.server.config.* -import io.ktor.http.* -import io.ktor.response.* -import io.ktor.routing.* import io.ktor.server.engine.* +import io.ktor.server.response.* +import io.ktor.server.routing.* import io.ktor.server.testing.* import io.ktor.util.* import kotlinx.coroutines.* @@ -494,7 +494,7 @@ class ApplicationEngineEnvironmentReloadingTests { @Test fun `interceptor is invoked when added before environment start`() { val engine = TestApplicationEngine(createTestEnvironment()) - engine.application.intercept(ApplicationCallPipeline.Features) { + engine.application.intercept(ApplicationCallPipeline.Plugins) { call.response.header("Custom", "Value") } engine.start() diff --git a/ktor-server/ktor-server-netty/jvm/src/io/ktor/server/netty/NettyApplicationCall.kt b/ktor-server/ktor-server-netty/jvm/src/io/ktor/server/netty/NettyApplicationCall.kt index fbcec384da8..43b06dc8fa2 100644 --- a/ktor-server/ktor-server-netty/jvm/src/io/ktor/server/netty/NettyApplicationCall.kt +++ b/ktor-server/ktor-server-netty/jvm/src/io/ktor/server/netty/NettyApplicationCall.kt @@ -18,7 +18,9 @@ public abstract class NettyApplicationCall( private val requestMessage: Any ) : BaseApplicationCall(application) { + @OptIn(InternalAPI::class) public abstract override val request: NettyApplicationRequest + @OptIn(InternalAPI::class) public abstract override val response: NettyApplicationResponse public val responseWriteJob: Job = Job() @@ -31,6 +33,7 @@ public abstract class NettyApplicationCall( internal suspend fun finish() { try { + @OptIn(InternalAPI::class) response.ensureResponseSent() } catch (cause: Throwable) { finishComplete() @@ -53,12 +56,14 @@ public abstract class NettyApplicationCall( } } + @OptIn(InternalAPI::class) private fun finishComplete() { responseWriteJob.cancel() request.close() releaseRequestMessage() } + @OptIn(InternalAPI::class) internal fun dispose() { response.close() request.close() diff --git a/ktor-server/ktor-server-netty/jvm/src/io/ktor/server/netty/NettyApplicationCallHandler.kt b/ktor-server/ktor-server-netty/jvm/src/io/ktor/server/netty/NettyApplicationCallHandler.kt index 45c5a0d7126..1ff41d3b19e 100644 --- a/ktor-server/ktor-server-netty/jvm/src/io/ktor/server/netty/NettyApplicationCallHandler.kt +++ b/ktor-server/ktor-server-netty/jvm/src/io/ktor/server/netty/NettyApplicationCallHandler.kt @@ -9,6 +9,7 @@ import io.ktor.http.HttpHeaders import io.ktor.server.application.* import io.ktor.server.engine.* import io.ktor.server.netty.http1.* +import io.ktor.util.* import io.ktor.util.pipeline.* import io.ktor.utils.io.* import io.netty.channel.* diff --git a/ktor-server/ktor-server-netty/jvm/src/io/ktor/server/netty/NettyApplicationRequest.kt b/ktor-server/ktor-server-netty/jvm/src/io/ktor/server/netty/NettyApplicationRequest.kt index e37fd4fb6a6..9ff3ae2cee7 100644 --- a/ktor-server/ktor-server-netty/jvm/src/io/ktor/server/netty/NettyApplicationRequest.kt +++ b/ktor-server/ktor-server-netty/jvm/src/io/ktor/server/netty/NettyApplicationRequest.kt @@ -17,8 +17,6 @@ import kotlinx.coroutines.* import java.io.* import kotlin.coroutines.* -@Suppress("KDocMissingDocumentation") -@InternalAPI public abstract class NettyApplicationRequest( call: ApplicationCall, override val coroutineContext: CoroutineContext, diff --git a/ktor-server/ktor-server-netty/jvm/src/io/ktor/server/netty/NettyApplicationRequestHeaders.kt b/ktor-server/ktor-server-netty/jvm/src/io/ktor/server/netty/NettyApplicationRequestHeaders.kt index fbb50e693f3..af985e8d803 100644 --- a/ktor-server/ktor-server-netty/jvm/src/io/ktor/server/netty/NettyApplicationRequestHeaders.kt +++ b/ktor-server/ktor-server-netty/jvm/src/io/ktor/server/netty/NettyApplicationRequestHeaders.kt @@ -9,8 +9,6 @@ import io.ktor.util.* import io.netty.handler.codec.http.* import io.netty.handler.codec.http.HttpHeaders -@InternalAPI -@Suppress("KDocMissingDocumentation") public class NettyApplicationRequestHeaders(request: HttpRequest) : Headers { private val headers: HttpHeaders = request.headers() override fun get(name: String): String? = headers.get(name) diff --git a/ktor-server/ktor-server-netty/jvm/src/io/ktor/server/netty/NettyApplicationResponse.kt b/ktor-server/ktor-server-netty/jvm/src/io/ktor/server/netty/NettyApplicationResponse.kt index 2238ac3a436..22152bf024e 100644 --- a/ktor-server/ktor-server-netty/jvm/src/io/ktor/server/netty/NettyApplicationResponse.kt +++ b/ktor-server/ktor-server-netty/jvm/src/io/ktor/server/netty/NettyApplicationResponse.kt @@ -73,20 +73,20 @@ public abstract class NettyApplicationResponse( protected open fun responseMessage(chunked: Boolean, data: ByteArray): Any = responseMessage(chunked, true) internal fun sendResponse(chunked: Boolean = true, content: ByteReadChannel) { - if (!responseMessageSent) { - responseChannel = content - responseMessage.complete( - when { - content.isClosedForRead -> { - responseMessage(chunked = false, data = EmptyByteArray) - } - else -> { - responseMessage(chunked, last = false) - } + if (responseMessageSent) return + + responseChannel = content + responseMessage.complete( + when { + content.isClosedForRead -> { + responseMessage(chunked = false, data = EmptyByteArray) } - ) - responseMessageSent = true - } + else -> { + responseMessage(chunked, last = false) + } + } + ) + responseMessageSent = true } internal fun ensureResponseSent() { diff --git a/ktor-server/ktor-server-netty/jvm/src/io/ktor/server/netty/http1/NettyHttp1ApplicationRequest.kt b/ktor-server/ktor-server-netty/jvm/src/io/ktor/server/netty/http1/NettyHttp1ApplicationRequest.kt index 4e68b2ea062..a85f0239afe 100644 --- a/ktor-server/ktor-server-netty/jvm/src/io/ktor/server/netty/http1/NettyHttp1ApplicationRequest.kt +++ b/ktor-server/ktor-server-netty/jvm/src/io/ktor/server/netty/http1/NettyHttp1ApplicationRequest.kt @@ -14,7 +14,6 @@ import io.netty.handler.codec.http.* import io.netty.handler.codec.http.multipart.* import kotlin.coroutines.* -@OptIn(InternalAPI::class) internal class NettyHttp1ApplicationRequest( call: ApplicationCall, coroutineContext: CoroutineContext, diff --git a/ktor-server/ktor-server-netty/jvm/src/io/ktor/server/netty/http1/NettyHttp1ApplicationResponse.kt b/ktor-server/ktor-server-netty/jvm/src/io/ktor/server/netty/http1/NettyHttp1ApplicationResponse.kt index 28ceadd19f8..010be9a4f3b 100644 --- a/ktor-server/ktor-server-netty/jvm/src/io/ktor/server/netty/http1/NettyHttp1ApplicationResponse.kt +++ b/ktor-server/ktor-server-netty/jvm/src/io/ktor/server/netty/http1/NettyHttp1ApplicationResponse.kt @@ -6,11 +6,9 @@ package io.ktor.server.netty.http1 import io.ktor.http.* import io.ktor.http.content.* -import io.ktor.server.engine.* import io.ktor.server.netty.* import io.ktor.server.netty.cio.* import io.ktor.server.response.* -import io.ktor.util.* import io.ktor.utils.io.* import io.netty.buffer.* import io.netty.channel.* diff --git a/ktor-server/ktor-server-plugins/ktor-server-double-receive/jvm/src/io/ktor/server/plugins/DoubleReceive.kt b/ktor-server/ktor-server-plugins/ktor-server-double-receive/jvm/src/io/ktor/server/plugins/DoubleReceive.kt index 7fab8722467..caec2cc5e83 100644 --- a/ktor-server/ktor-server-plugins/ktor-server-double-receive/jvm/src/io/ktor/server/plugins/DoubleReceive.kt +++ b/ktor-server/ktor-server-plugins/ktor-server-double-receive/jvm/src/io/ktor/server/plugins/DoubleReceive.kt @@ -114,7 +114,8 @@ private fun CachedTransformationResult<*>?.isByteArray(): Boolean { private fun ApplicationReceiveRequest.checkAlreadyConsumedOrWrongType(requestType: TypeInfo) { when { value is CachedTransformationResult.Success<*> -> throw RequestAlreadyConsumedException() - requestType.kotlinType?.jvmErasure?.isInstance(value) != true -> throw CannotTransformContentToTypeException(requestType.kotlinType!!) + requestType.kotlinType?.jvmErasure?.isInstance(value) != true -> + throw CannotTransformContentToTypeException(requestType.kotlinType!!) } } diff --git a/ktor-server/ktor-server-servlet/jvm/test/io/ktor/tests/servlet/HoconTest.kt b/ktor-server/ktor-server-servlet/jvm/test/io/ktor/tests/servlet/HoconTest.kt index 7a77fedafaa..8503f336370 100644 --- a/ktor-server/ktor-server-servlet/jvm/test/io/ktor/tests/servlet/HoconTest.kt +++ b/ktor-server/ktor-server-servlet/jvm/test/io/ktor/tests/servlet/HoconTest.kt @@ -4,7 +4,7 @@ package io.ktor.tests.servlet -import io.ktor.application.* +import io.ktor.server.application.* import io.ktor.server.engine.* import io.ktor.server.servlet.* import io.ktor.server.servlet.ServletApplicationEngine.Companion.ApplicationEngineEnvironmentAttributeKey diff --git a/ktor-server/ktor-server-test-suites/jvm/src/io/ktor/server/testing/suites/ConnectionTestSuite.kt b/ktor-server/ktor-server-test-suites/jvm/src/io/ktor/server/testing/suites/ConnectionTestSuite.kt index 62986a31a6a..ad00eb098e0 100644 --- a/ktor-server/ktor-server-test-suites/jvm/src/io/ktor/server/testing/suites/ConnectionTestSuite.kt +++ b/ktor-server/ktor-server-test-suites/jvm/src/io/ktor/server/testing/suites/ConnectionTestSuite.kt @@ -7,8 +7,9 @@ package io.ktor.server.testing.suites import io.ktor.server.engine.* import io.ktor.util.network.* import kotlinx.coroutines.* +import org.junit.* +import org.junit.Assert.* import java.net.* -import kotlin.test.* abstract class ConnectionTestSuite(val engine: ApplicationEngineFactory<*, *>) { diff --git a/ktor-server/ktor-server-test-suites/jvm/src/io/ktor/server/testing/suites/HttpServerTestSuite.kt b/ktor-server/ktor-server-test-suites/jvm/src/io/ktor/server/testing/suites/HttpServerTestSuite.kt index 749b3210585..b175a6f4a34 100644 --- a/ktor-server/ktor-server-test-suites/jvm/src/io/ktor/server/testing/suites/HttpServerTestSuite.kt +++ b/ktor-server/ktor-server-test-suites/jvm/src/io/ktor/server/testing/suites/HttpServerTestSuite.kt @@ -801,8 +801,7 @@ abstract class HttpServerTestSuite()) } parent.cancel() diff --git a/ktor-server/ktor-server-tomcat/jvm/test/io/ktor/tests/server/tomcat/TomcatEngineTest.kt b/ktor-server/ktor-server-tomcat/jvm/test/io/ktor/tests/server/tomcat/TomcatEngineTest.kt index 6e11175d5c1..cfbf1edbbb4 100644 --- a/ktor-server/ktor-server-tomcat/jvm/test/io/ktor/tests/server/tomcat/TomcatEngineTest.kt +++ b/ktor-server/ktor-server-tomcat/jvm/test/io/ktor/tests/server/tomcat/TomcatEngineTest.kt @@ -161,6 +161,8 @@ class TomcatClientCertTest : trustStore = ca.trustStore(trustStorePath) this.trustStorePath = trustStorePath } + } +} class TomcatServerPluginsTest : ServerPluginsTestSuite(Tomcat) { diff --git a/ktor-server/ktor-server/jvm/test-resources/error404.html b/ktor-server/ktor-server/jvm/test-resources/error404.html deleted file mode 100644 index 218f3f81087..00000000000 --- a/ktor-server/ktor-server/jvm/test-resources/error404.html +++ /dev/null @@ -1 +0,0 @@ -error 404 \ No newline at end of file diff --git a/ktor-server/ktor-server/jvm/test-resources/logback-test.xml b/ktor-server/ktor-server/jvm/test-resources/logback-test.xml deleted file mode 100644 index e0bcc1db200..00000000000 --- a/ktor-server/ktor-server/jvm/test-resources/logback-test.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - %d{YYYY-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n - - - - - - - - - - - - - - diff --git a/ktor-server/ktor-server/jvm/test-resources/testjar.jar b/ktor-server/ktor-server/jvm/test-resources/testjar.jar deleted file mode 100644 index 429ceb1fdcc515e9905001b65f1c5c61d19ddf9d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 559 zcmWIWW@Zs#;Nak3_#V&|z<>le8CV#6T|*poJ^kGD|D9rBU}gyLX6FE@V1g() - mapConfig["auth.hashAlgorithm"] = "SHA-256" - mapConfig["auth.salt"] = "ktor" - mapConfig["auth.users"] = listOf(mapOf("name" to "test")) - - mapConfig["auth.values"] = listOf("a", "b") - mapConfig["auth.listValues"] = listOf("a", "b", "c") - - mapConfig["auth.data"] = mapOf("value1" to "1", "value2" to "2") - - val config = HoconApplicationConfig(ConfigFactory.parseMap(mapConfig)) - val keys = config.keys() - assertEquals( - keys, - setOf( - "auth.hashAlgorithm", - "auth.salt", - "auth.users", - "auth.values", - "auth.listValues", - "auth.data.value1", - "auth.data.value2" - ) - ) - } - - @Test - fun testKeysNestedHoconConfig() { - val mapConfig = mutableMapOf() - mapConfig["auth.nested.data"] = mapOf("value1" to "1", "value2" to "2") - mapConfig["auth.nested.list"] = listOf("a", "b") - mapConfig["auth.data1.value1"] = "1" - - val config = HoconApplicationConfig(ConfigFactory.parseMap(mapConfig)) - val nestedConfig = config.config("auth.nested") - val keys = nestedConfig.keys() - assertEquals(keys, setOf("data.value1", "data.value2", "list")) - assertEquals("1", nestedConfig.property("data.value1").getString()) - assertEquals("2", nestedConfig.property("data.value2").getString()) - assertEquals(listOf("a", "b"), nestedConfig.property("list").getList()) - } -} diff --git a/ktor-server/ktor-server/jvm/test/io/ktor/tests/http/FindContainingJarFileTest.kt b/ktor-server/ktor-server/jvm/test/io/ktor/tests/http/FindContainingJarFileTest.kt deleted file mode 100644 index 9a488178715..00000000000 --- a/ktor-server/ktor-server/jvm/test/io/ktor/tests/http/FindContainingJarFileTest.kt +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2014-2019 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. - */ - -package io.ktor.tests.http - -import io.ktor.server.http.content.* -import kotlin.test.* - -class FindContainingJarFileTest { - @Test - fun testSimpleJar() { - assertEquals("/dist/app.jar", findContainingJarFile("jar:file:/dist/app.jar!/test").path.replace('\\', '/')) - } - - @Test - fun testSimpleJarNoFile() { - assertEquals("/dist/app.jar", findContainingJarFile("jar:file:/dist/app.jar!").path.replace('\\', '/')) - } - - @Test - fun testEscapedChars() { - assertEquals( - "/Program Files/app.jar", - findContainingJarFile("jar:file:/Program%20Files/app.jar!/test") - .path.replace('\\', '/') - ) - } -} diff --git a/ktor-server/ktor-server/jvm/test/io/ktor/tests/http/ParametersTest.kt b/ktor-server/ktor-server/jvm/test/io/ktor/tests/http/ParametersTest.kt deleted file mode 100644 index 481731071b7..00000000000 --- a/ktor-server/ktor-server/jvm/test/io/ktor/tests/http/ParametersTest.kt +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright 2014-2019 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. - */ - -package io.ktor.tests.http - -import io.ktor.http.* -import io.ktor.server.util.* -import kotlin.test.* - -class ParametersTest { - private val parameters = parametersOf( - "single" to listOf("a"), - "another" to listOf("2"), - "multiple" to listOf("3", "4") - ) - - @Test - fun testSingleValues() { - val single: String by parameters - val another: Int by parameters - - assertEquals("a", single) - assertEquals(2, another) - } - - @Test - fun testMultipleAsStrings() { - val multiple: List by parameters - - assertEquals(listOf("3", "4"), multiple) - } - - @Test - fun testMultipleAsStringsVariance() { - val multiple: MutableList by parameters - - assertEquals(listOf("3", "4"), multiple.toList()) - } - - @Test - fun testMultipleAsIntegers() { - val multiple: List by parameters - - assertEquals(listOf(3, 4), multiple) - } - - @Test - fun testMultipleAsLongIntegers() { - val multiple: List by parameters - - assertEquals(listOf(3L, 4L), multiple) - } -} diff --git a/ktor-server/ktor-server/jvm/test/io/ktor/tests/http/PathNormalizationTest.kt b/ktor-server/ktor-server/jvm/test/io/ktor/tests/http/PathNormalizationTest.kt deleted file mode 100644 index 93459195773..00000000000 --- a/ktor-server/ktor-server/jvm/test/io/ktor/tests/http/PathNormalizationTest.kt +++ /dev/null @@ -1,142 +0,0 @@ -/* - * Copyright 2014-2019 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. - */ - -package io.ktor.tests.http - -import io.ktor.server.util.* -import java.util.* -import kotlin.test.* - -class PathNormalizationTest { - @Test - fun testEmpty() { - assertEquals(emptyList(), listOf().normalizePathComponents()) - assertEquals(emptyList(), listOf("").normalizePathComponents()) - assertEquals(emptyList(), listOf("", "").normalizePathComponents()) - assertEquals(emptyList(), listOf(".").normalizePathComponents()) - assertEquals(emptyList(), listOf(".", ".").normalizePathComponents()) - assertEquals(emptyList(), listOf(".", ".", ".").normalizePathComponents()) - assertEquals(emptyList(), listOf(".", "..", ".").normalizePathComponents()) - assertEquals(emptyList(), listOf("..").normalizePathComponents()) - assertEquals(emptyList(), listOf("..", "..").normalizePathComponents()) - assertEquals(emptyList(), listOf("..", "..", "..").normalizePathComponents()) - } - - @Test - fun testDirUp() { - assertEquals(listOf("a"), listOf("a").normalizePathComponents()) - assertEquals(listOf("a"), listOf("..", "a").normalizePathComponents()) - assertEquals(listOf("a"), listOf("..", "..", "a").normalizePathComponents()) - assertEquals(listOf(), listOf("a", "..").normalizePathComponents()) - assertEquals(listOf(), listOf("a", "..", "..").normalizePathComponents()) - assertEquals(listOf("b"), listOf("a", "..", "..", "b").normalizePathComponents()) - - assertEquals(listOf("a", "b"), listOf("a", "b").normalizePathComponents()) - assertEquals(listOf("a"), listOf("a", "b", "..").normalizePathComponents()) - assertEquals(listOf(), listOf("a", "b", "..", "..").normalizePathComponents()) - assertEquals(listOf(), listOf("a", "b", "..", "..", "..").normalizePathComponents()) - assertEquals(listOf(), listOf("a", "..", "b", "..").normalizePathComponents()) - assertEquals(listOf(), listOf("a", "..", "..", "b", "..").normalizePathComponents()) - assertEquals(listOf(), listOf("a", "..", "b", "..", "..").normalizePathComponents()) - assertEquals(listOf(), listOf("a", "..", "..", "b", "..", "..").normalizePathComponents()) - assertEquals(listOf(), generateSequence { ".." }.take(1000).toList().normalizePathComponents()) - } - - @Test - fun testNoOp() { - assertEquals(listOf(), listOf(".").normalizePathComponents()) - assertEquals(listOf(), listOf(".", ".").normalizePathComponents()) - assertEquals(listOf(), listOf(".", ".", ".").normalizePathComponents()) - assertEquals(listOf("a"), listOf("a").normalizePathComponents()) - assertEquals(listOf("a"), listOf("a", ".").normalizePathComponents()) - assertEquals(listOf("a"), listOf(".", "a").normalizePathComponents()) - assertEquals(listOf("a"), listOf(".", "a", ".").normalizePathComponents()) - assertEquals(listOf("a", "b"), listOf("a", "b").normalizePathComponents()) - assertEquals(listOf("a", "b"), listOf("a", ".", "b").normalizePathComponents()) - assertEquals(listOf("a", "b"), listOf("a", ".", "b", ".").normalizePathComponents()) - assertEquals(listOf("a", "b"), listOf(".", "a", ".", "b", ".").normalizePathComponents()) - } - - @Test - fun testComponentEndsWith() { - assertEquals(listOf("a"), listOf("a.").normalizePathComponents()) - assertEquals(listOf("a"), listOf("a..").normalizePathComponents()) - assertEquals(listOf("a"), listOf("a...").normalizePathComponents()) - - assertEquals(listOf("a"), listOf("a ").normalizePathComponents()) - assertEquals(listOf("a"), listOf("a ").normalizePathComponents()) - assertEquals(listOf("a"), listOf("a ").normalizePathComponents()) - assertEquals(listOf("a"), listOf("a .").normalizePathComponents()) - assertEquals(listOf("a"), listOf("a. ").normalizePathComponents()) - assertEquals(listOf("a"), listOf("a. . ").normalizePathComponents()) - assertEquals(listOf("a"), listOf("a . .").normalizePathComponents()) - - assertEquals(listOf("-", "a"), listOf("-", "a.").normalizePathComponents()) - assertEquals(listOf("-", "a"), listOf("-", "a ").normalizePathComponents()) - assertEquals(listOf("-", "a", "b"), listOf("-", "a.", "b.").normalizePathComponents()) - } - - @Test - fun testComponentWithNull() { - assertEquals(listOf("a"), listOf("a\u0000").normalizePathComponents()) - assertEquals(listOf("a", "b"), listOf("a", "b\u0000").normalizePathComponents()) - assertEquals(listOf("a", "b"), listOf("a\u0000", "b\u0000").normalizePathComponents()) - } - - @Test - fun testComponentWithTilde() { - assertEquals(listOf(), listOf("~").normalizePathComponents()) - assertEquals(listOf(), listOf("~", "~").normalizePathComponents()) - assertEquals(listOf("~test"), listOf("~test").normalizePathComponents()) - assertEquals(listOf("~~"), listOf("~~").normalizePathComponents()) - } - - @Test - fun testControlCharactersAndProhibited() { - val controlCharacters = '\u0000'..'\u001f' - val prohibitedCharacters = listOf('\\', '/', ':', '*', '?', '\"', '<', '>', '|') - - for (ch in controlCharacters + prohibitedCharacters) { - assertEquals(listOf(), listOf("$ch").normalizePathComponents()) - assertEquals(listOf(), listOf("$ch$ch").normalizePathComponents()) - assertEquals(listOf(), listOf("$ch$ch$ch").normalizePathComponents()) - assertEquals(listOf(), listOf("$ch", "$ch").normalizePathComponents()) - assertEquals(listOf("a"), listOf("${ch}a").normalizePathComponents()) - assertEquals(listOf("a"), listOf("a$ch").normalizePathComponents()) - assertEquals(listOf("ab"), listOf("a${ch}b").normalizePathComponents()) - assertEquals(listOf("ab"), listOf("a${ch}b", "$ch").normalizePathComponents()) - assertEquals(listOf("ab", "c"), listOf("a${ch}b", "$ch", "c").normalizePathComponents()) - } - } - - @Test - fun testWindowsDeviceNames() { - val names = listOf( - "CON", "PRN", "AUX", "NUL", - "COM1", "COM2", "COM3", "COM4", "COM5", "COM6", "COM7", "COM8", "COM9", - "LPT1", "LPT2", "LPT3", "LPT4", "LPT5", "LPT6", "LPT7", "LPT8", "LPT9" - ) - val allNames = names + names.map { it.lowercase(Locale.getDefault()) } + names.map { current -> - current.lowercase(Locale.getDefault()).replaceFirstChar { - if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() - } - } - - for (name in allNames) { - assertEquals(listOf(), listOf(name).normalizePathComponents()) - assertEquals(listOf(), listOf(name, name).normalizePathComponents()) - assertEquals(listOf("a"), listOf(name, "a", name).normalizePathComponents()) - assertEquals(listOf("a"), listOf(name, "a").normalizePathComponents()) - assertEquals(listOf("a"), listOf("a", name).normalizePathComponents()) - assertEquals(listOf("a", "b"), listOf("a", name, "b").normalizePathComponents()) - } - } - - @Test - fun testTrailingSpaces() { - assertEquals(listOf("a", "b"), listOf("a", ". ", "b").normalizePathComponents()) - assertEquals(listOf("a", "b"), listOf("a", ".. ", "b").normalizePathComponents()) - assertEquals(listOf("a", "b"), listOf("a", " ..", "b").normalizePathComponents()) - } -} diff --git a/ktor-server/ktor-server/jvm/test/io/ktor/tests/http/content/StaticContentResolutionTest.kt b/ktor-server/ktor-server/jvm/test/io/ktor/tests/http/content/StaticContentResolutionTest.kt deleted file mode 100644 index 23ad7ba14c2..00000000000 --- a/ktor-server/ktor-server/jvm/test/io/ktor/tests/http/content/StaticContentResolutionTest.kt +++ /dev/null @@ -1,42 +0,0 @@ -/* -* Copyright 2014-2021 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. -*/ - -package io.ktor.tests.http.content - -import io.ktor.http.* -import io.ktor.http.content.* -import io.ktor.server.http.content.* -import io.ktor.util.* -import kotlinx.coroutines.* -import java.net.* -import kotlin.test.* - -@OptIn(InternalAPI::class) -class StaticContentResolutionTest { - - private val baseUrl = StaticContentResolutionTest::class.java.classLoader.getResource("testjar.jar") - - @Test - fun testResourceClasspathResourceWithDirectoryInsideJar() { - val content = resourceClasspathResource(URL("jar:$baseUrl!/testdir"), "testdir") { - ContentType.defaultForFileExtension(it) - } - - assertNull(content) - } - - @Test - fun testResourceClasspathResourceWithFileInsideJar() { - val content = resourceClasspathResource(URL("jar:$baseUrl!/testdir/testfile"), "testdir/testfile") { - ContentType.defaultForFileExtension(it) - } - - assertNotNull(content) - assertTrue { content is OutgoingContent.ReadChannelContent } - with(content as OutgoingContent.ReadChannelContent) { - val data = String(runBlocking { readFrom().toByteArray() }) - assertEquals("test\n", data) - } - } -} diff --git a/ktor-server/ktor-server/jvm/test/io/ktor/tests/routing/RouteSelectorTest.kt b/ktor-server/ktor-server/jvm/test/io/ktor/tests/routing/RouteSelectorTest.kt deleted file mode 100644 index a70f8c389bc..00000000000 --- a/ktor-server/ktor-server/jvm/test/io/ktor/tests/routing/RouteSelectorTest.kt +++ /dev/null @@ -1,166 +0,0 @@ -/* -* Copyright 2014-2021 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. -*/ - -package io.ktor.tests.routing - -import io.ktor.server.routing.* -import kotlin.test.* - -internal class RouteSelectorTest { - - @Test - fun testEvaluateWithPrefixAndSuffixMatched() { - val evaluation = evaluatePathSegmentParameter( - segments = listOf("prefixPARAMsuffix"), - segmentIndex = 0, - name = "param", - prefix = "prefix", - suffix = "suffix", - isOptional = false - ) - - assertTrue(evaluation is RouteSelectorEvaluation.Success) - assertEquals(evaluation.quality, RouteSelectorEvaluation.qualityParameterWithPrefixOrSuffix) - assertEquals(evaluation.succeeded, true) - assertEquals(evaluation.parameters["param"], "PARAM") - } - - @Test - fun testEvaluateWithPrefixNotMatched() { - val evaluation = evaluatePathSegmentParameter( - segments = listOf("1prefixPARAMsuffix"), - segmentIndex = 0, - name = "param", - prefix = "prefix", - suffix = "suffix", - isOptional = false - ) - - assertEquals(evaluation, RouteSelectorEvaluation.FailedPath) - } - - @Test - fun testEvaluateWithSuffixNotMatched() { - val evaluation = evaluatePathSegmentParameter( - segments = listOf("prefixPARAMsuffix1"), - segmentIndex = 0, - name = "param", - prefix = "prefix", - suffix = "suffix", - isOptional = false - ) - - assertEquals(evaluation, RouteSelectorEvaluation.FailedPath) - } - - @Test - fun testEvaluateWithoutPrefixOrSuffix() { - val evaluation = evaluatePathSegmentParameter( - segments = listOf("PARAM"), - segmentIndex = 0, - name = "param", - isOptional = false - ) - - assertTrue(evaluation is RouteSelectorEvaluation.Success) - assertEquals(evaluation.succeeded, true) - assertEquals(evaluation.quality, RouteSelectorEvaluation.qualityParameter) - } - - @Test - fun testEvaluateWithSegmentIndexOutsideOfSegments() { - val evaluation = evaluatePathSegmentParameter( - segments = listOf("prefixPARAMsuffix"), - segmentIndex = 1, - name = "param", - prefix = "prefix", - suffix = "suffix", - isOptional = false - ) - - assertEquals(evaluation, RouteSelectorEvaluation.FailedPath) - } - - @Test - fun testEvaluateWithPrefixNotMatchedOptional() { - val evaluation = evaluatePathSegmentParameter( - segments = listOf("1prefixPARAMsuffix"), - segmentIndex = 0, - name = "param", - prefix = "prefix", - suffix = "suffix", - isOptional = true - ) - - assertEquals(evaluation, RouteSelectorEvaluation.Missing) - } - - @Test - fun testEvaluateWithSuffixNotMatchedOptional() { - val evaluation = evaluatePathSegmentParameter( - segments = listOf("prefixPARAMsuffix1"), - segmentIndex = 0, - name = "param", - prefix = "prefix", - suffix = "suffix", - isOptional = true - ) - - assertEquals(evaluation, RouteSelectorEvaluation.Missing) - } - - @Test - fun testEvaluateWithSegmentIndexOutsideOfSegmentsOptional() { - val evaluation = evaluatePathSegmentParameter( - segments = listOf("prefixPARAMsuffix"), - segmentIndex = 1, - name = "param", - prefix = "prefix", - suffix = "suffix", - isOptional = true - ) - - assertEquals(evaluation, RouteSelectorEvaluation.Missing) - } - - @Test - fun testEvaluateWithTrailingSlashAndOptional() { - val evaluation = evaluatePathSegmentParameter( - segments = listOf("foo", ""), - segmentIndex = 1, - name = "param", - isOptional = true - ) - - assertEquals( - evaluation, - RouteSelectorEvaluation - .Success(RouteSelectorEvaluation.qualityMissing, segmentIncrement = 1) - ) - } - - @Test - fun testEvaluateWithoutTrailingSlashAndOptional() { - val evaluation = evaluatePathSegmentParameter( - segments = listOf("foo"), - segmentIndex = 1, - name = "param", - isOptional = true - ) - - assertEquals(evaluation, RouteSelectorEvaluation.Missing) - } - - @Test - fun testEvaluateWithTrailingSlashAndNonOptional() { - val evaluation = evaluatePathSegmentParameter( - segments = listOf("foo", ""), - segmentIndex = 1, - name = "param", - isOptional = false - ) - - assertEquals(evaluation, RouteSelectorEvaluation.FailedPath) - } -} diff --git a/ktor-server/ktor-server/jvm/test/io/ktor/tests/routing/RouteTest.kt b/ktor-server/ktor-server/jvm/test/io/ktor/tests/routing/RouteTest.kt deleted file mode 100644 index 4b3da4e48b6..00000000000 --- a/ktor-server/ktor-server/jvm/test/io/ktor/tests/routing/RouteTest.kt +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2014-2021 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. - */ - -package io.ktor.tests.routing - -import io.ktor.server.routing.* -import kotlin.test.* - -class RouteTest { - - @Test - fun testToStringSimple() { - val root = Route(parent = null, selector = PathSegmentConstantRouteSelector("root")) - val simpleChild = Route(parent = root, selector = PathSegmentConstantRouteSelector("simpleChild")) - val simpleGrandChild = - Route(parent = simpleChild, selector = PathSegmentConstantRouteSelector("simpleGrandChild")) - - val slashChild = Route(parent = root, selector = TrailingSlashRouteSelector) - val slashGrandChild = Route(parent = slashChild, selector = TrailingSlashRouteSelector) - val simpleChildInSlash = Route(parent = slashGrandChild, PathSegmentConstantRouteSelector("simpleChildInSlash")) - val slashChildInSimpleChild = Route(parent = simpleChildInSlash, TrailingSlashRouteSelector) - - assertEquals("/root", root.toString()) - assertEquals("/root/simpleChild", simpleChild.toString()) - assertEquals("/root/simpleChild/simpleGrandChild", simpleGrandChild.toString()) - assertEquals("/root/", slashChild.toString()) - assertEquals("/root/", slashGrandChild.toString()) - assertEquals("/root/simpleChildInSlash", simpleChildInSlash.toString()) - assertEquals("/root/simpleChildInSlash/", slashChildInSimpleChild.toString()) - } -} diff --git a/ktor-server/ktor-server/jvm/test/io/ktor/tests/utils/CopyOnWriteHashMapTest.kt b/ktor-server/ktor-server/jvm/test/io/ktor/tests/utils/CopyOnWriteHashMapTest.kt deleted file mode 100644 index 08d62d0a470..00000000000 --- a/ktor-server/ktor-server/jvm/test/io/ktor/tests/utils/CopyOnWriteHashMapTest.kt +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright 2014-2019 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. - */ - -package io.ktor.tests.utils - -import io.ktor.server.util.* -import kotlin.test.* - -@OptIn(InternalAPI::class) -class CopyOnWriteHashMapTest { - private val map = CopyOnWriteHashMap() - - @Test - fun smoke() { - assertEquals(null, map["k1"]) - map["k1"] = "v1" - assertEquals("v1", map["k1"]) - - assertEquals(null, map["k2"]) - assertEquals(null, map.put("k2", "v2")) - assertEquals("v2", map.put("k2", "v3")) - assertEquals("v3", map.remove("k2")) - - assertEquals("v31", map.computeIfAbsent("k3") { "v31" }) - assertEquals("v31", map.computeIfAbsent("k3") { "v32" }) - } - - @Test - fun getEmpty() { - assertNull(map["k1"]) - } - - @Test - fun getExisting() { - map.put("k1", "v1") - assertEquals("v1", map["k1"]) - } - - @Test - fun putNewAndReplace() { - assertEquals(null, map.put("k1", "v1")) - assertEquals("v1", map.put("k1", "v2")) - assertEquals("v2", map.put("k1", "v3")) - assertEquals("v3", map["k1"]) - } - - @Test - fun putMany() { - repeat(100) { - assertNull(map.put("k-$it", "v-$it")) - } - - repeat(100) { - assertEquals("v-$it", map["k-$it"]) - } - } - - @Test - fun testRemoveMissing() { - assertNull(map["k"]) - assertNull(map.remove("k")) - assertNull(map["k"]) - } - - @Test - fun testRemoveExisting() { - map.put("k1", "v1") - assertEquals("v1", map.remove("k1")) - assertNull(map.remove("k1")) - assertNull(map["k1"]) - } - - @Test - fun testRemoveOnlySpecified() { - map.put("k1", "v1") - map.put("k2", "v2") - - assertEquals("v1", map["k1"]) - assertEquals("v2", map["k2"]) - assertEquals("v1", map.remove("k1")) - assertEquals(null, map["k1"]) - assertEquals("v2", map["k2"]) - } - - @Test - fun testComputeIfAbsentMissing() { - assertNull(map["k1"]) - assertEquals("v1", map.computeIfAbsent("k1") { "v1" }) - assertEquals("v1", map["k1"]) - } - - @Test - fun testComputeIfAbsentExisting() { - map.put("k1", "v0") - assertEquals("v0", map.computeIfAbsent("k1") { fail("shouldn't be invoked") }) - assertEquals("v0", map["k1"]) - } -} diff --git a/ktor-server/ktor-server/jvm/test/io/ktor/tests/utils/DateJvmTest.kt b/ktor-server/ktor-server/jvm/test/io/ktor/tests/utils/DateJvmTest.kt deleted file mode 100644 index cdb70e2c784..00000000000 --- a/ktor-server/ktor-server/jvm/test/io/ktor/tests/utils/DateJvmTest.kt +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 2014-2019 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. - */ - -package io.ktor.tests.utils - -import io.ktor.server.util.date.* -import io.ktor.util.date.* -import java.text.SimpleDateFormat -import java.time.OffsetDateTime -import java.time.ZoneOffset -import java.util.* -import kotlin.test.* - -class DateJvmTest { - @Test - fun testJvmDate() { - val dateRaw = GMTDate(1346524199000) - val date = dateRaw.toJvmDate() - - assertEquals(dateRaw.timestamp, date.time) - } - - @Test - fun testJvmDateWithOffSetDateTime() { - val dateRaw = GMTDate(20, 20, 20, 20, Month.FEBRUARY, 20) - val date: OffsetDateTime = OffsetDateTime.of( - dateRaw.year, - dateRaw.month.ordinal + 1, - dateRaw.dayOfMonth - 2, - dateRaw.hours, - dateRaw.minutes, - dateRaw.seconds, - 0, - ZoneOffset.UTC - ) - - assertEquals(dateRaw.toJvmDate(), date.toInstant().toGMTDate().toJvmDate()) - } - - @Test - fun testJvmDateWithZoneOffset() { - val gmtDate: GMTDate = GMTDate(0, 0, 12, 1, Month.JANUARY, 2019) - val convertedDate = gmtDate.toJvmDate().toInstant().atZone(ZoneOffset.systemDefault()) - assertEquals(convertedDate.toGMTDate(), gmtDate) - } - - @Test - fun testJvmDateWithSimpleDateFormat() { - val dateFormat: SimpleDateFormat = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss") - dateFormat.timeZone = TimeZone.getTimeZone(ZoneOffset.systemDefault()) - val date = dateFormat.parse("2019-01-01T12:00:00").toInstant() - - val gmtDate: GMTDate = GMTDate(0, 0, 12, 1, Month.JANUARY, 2019) - val format: Long = dateFormat.timeZone.getOffset(gmtDate.timestamp).toLong() - val convertedDate = gmtDate.toJvmDate().toInstant().minusMillis(format) - - assertEquals(date, convertedDate) - } -} diff --git a/ktor-shared/build.gradle b/ktor-shared/build.gradle deleted file mode 100644 index a35c1b53e40..00000000000 --- a/ktor-shared/build.gradle +++ /dev/null @@ -1,9 +0,0 @@ -description = 'shared functionality for client and server' - -subprojects { - kotlin.sourceSets { - commonMain.dependencies { - api project(':ktor-http') - } - } -} diff --git a/ktor-shared/build.gradle.kts b/ktor-shared/build.gradle.kts new file mode 100644 index 00000000000..650bb35d547 --- /dev/null +++ b/ktor-shared/build.gradle.kts @@ -0,0 +1,11 @@ +description = "Shared functionality for client and server" + +subprojects { + kotlin.sourceSets { + val commonMain by getting { + dependencies { + api(project(":ktor-http")) + } + } + } +} diff --git a/ktor-shared/common/.gitkeep b/ktor-shared/common/.gitkeep deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/ktor-shared/js/.gitkeep b/ktor-shared/js/.gitkeep deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/ktor-shared/posix/.gitkeep b/ktor-shared/posix/.gitkeep deleted file mode 100644 index e69de29bb2d..00000000000