Skip to content

Commit

Permalink
KTOR-4834 Fix startup message on Windows (#3157)
Browse files Browse the repository at this point in the history
* KTOR-4834 Fix startup message on Windows
  • Loading branch information
e5l authored Sep 8, 2022
1 parent 3b31017 commit d300441
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 4 deletions.
2 changes: 1 addition & 1 deletion ktor-client/ktor-client-core/common/test/CookiesTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -402,8 +402,6 @@ class ContentNegotiationTests {
}
}



object Thing

data class StringWrapper(val value: String)
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
}
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit d300441

Please sign in to comment.