diff --git a/ktor-client/ktor-client-core/common/test/CookiesTest.kt b/ktor-client/ktor-client-core/common/test/CookiesTest.kt index 6883ac6a62b..9403b357b2f 100644 --- a/ktor-client/ktor-client-core/common/test/CookiesTest.kt +++ b/ktor-client/ktor-client-core/common/test/CookiesTest.kt @@ -43,7 +43,7 @@ class CookiesTest { } @Test - fun testCookiesAreRenderedWithSpaceInBetween() = testSuspend{ + fun testCookiesAreRenderedWithSpaceInBetween() = testSuspend { var storage = AcceptAllCookiesStorage() storage.addCookie("http://localhost/", Cookie("name1", "value1")) storage.addCookie("http://localhost/", Cookie("name2", "value2")) diff --git a/ktor-client/ktor-client-plugins/ktor-client-content-negotiation/common/test/io/ktor/client/plugins/ContentNegotiationTests.kt b/ktor-client/ktor-client-plugins/ktor-client-content-negotiation/common/test/io/ktor/client/plugins/ContentNegotiationTests.kt index c00ec9a0584..f67af2b4cb8 100644 --- a/ktor-client/ktor-client-plugins/ktor-client-content-negotiation/common/test/io/ktor/client/plugins/ContentNegotiationTests.kt +++ b/ktor-client/ktor-client-plugins/ktor-client-content-negotiation/common/test/io/ktor/client/plugins/ContentNegotiationTests.kt @@ -402,8 +402,6 @@ class ContentNegotiationTests { } } - - object Thing data class StringWrapper(val value: String) diff --git a/ktor-server/ktor-server-host-common/jvm/src/io/ktor/server/engine/internal/EngineUtilsJvm.kt b/ktor-server/ktor-server-host-common/jvm/src/io/ktor/server/engine/internal/EngineUtilsJvm.kt new file mode 100644 index 00000000000..acf6e3f2069 --- /dev/null +++ b/ktor-server/ktor-server-host-common/jvm/src/io/ktor/server/engine/internal/EngineUtilsJvm.kt @@ -0,0 +1,15 @@ +/* + * Copyright 2014-2022 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. + */ + +package io.ktor.server.engine.internal + +private val OS_NAME = System.getProperty("os.name", "") + .lowercase() + +internal actual fun escapeHostname(value: String): String { + if (!OS_NAME.contains("windows")) return value + if (value != "0.0.0.0") return value + + return "127.0.0.1" +} diff --git a/ktor-server/ktor-server-host-common/jvmAndNix/src/io/ktor/server/engine/BaseApplicationEngine.kt b/ktor-server/ktor-server-host-common/jvmAndNix/src/io/ktor/server/engine/BaseApplicationEngine.kt index 1b4a77fc032..6abddaae7af 100644 --- a/ktor-server/ktor-server-host-common/jvmAndNix/src/io/ktor/server/engine/BaseApplicationEngine.kt +++ b/ktor-server/ktor-server-host-common/jvmAndNix/src/io/ktor/server/engine/BaseApplicationEngine.kt @@ -72,8 +72,9 @@ public abstract class BaseApplicationEngine( val log = environment.log CoroutineScope(environment.application.coroutineContext).launch { connectors.await().forEach { + val host = escapeHostname(it.host) log.info( - "Responding at ${it.type.name.lowercase()}://${it.host}:${it.port}" + "Responding at ${it.type.name.lowercase()}://$host:${it.port}" ) } } diff --git a/ktor-server/ktor-server-host-common/jvmAndNix/src/io/ktor/server/engine/internal/EngineUtils.kt b/ktor-server/ktor-server-host-common/jvmAndNix/src/io/ktor/server/engine/internal/EngineUtils.kt new file mode 100644 index 00000000000..6f4e9c9c19d --- /dev/null +++ b/ktor-server/ktor-server-host-common/jvmAndNix/src/io/ktor/server/engine/internal/EngineUtils.kt @@ -0,0 +1,7 @@ +/* + * Copyright 2014-2022 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. + */ + +package io.ktor.server.engine.internal + +internal expect fun escapeHostname(value: String): String diff --git a/ktor-server/ktor-server-host-common/nix/src/io/ktor/server/engine/internal/EngineUtilsNix.kt b/ktor-server/ktor-server-host-common/nix/src/io/ktor/server/engine/internal/EngineUtilsNix.kt new file mode 100644 index 00000000000..0e3db378896 --- /dev/null +++ b/ktor-server/ktor-server-host-common/nix/src/io/ktor/server/engine/internal/EngineUtilsNix.kt @@ -0,0 +1,7 @@ +/* + * Copyright 2014-2022 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. + */ + +package io.ktor.server.engine.internal + +internal actual fun escapeHostname(value: String): String = value