Открыть боковую панель
Aurora OS
Kotlin Multiplatform
Libraries
ktor
Коммиты
7f0979ac
Не подтверждена
Коммит
7f0979ac
создал
Фев 12, 2025
по автору
Leonid Stashevsky
Зафиксировано автором
GitHub
Фев 12, 2025
Просмотр файлов
KTOR-6671 Fix Resources: a / route isn't resolved when there is a sibling (#4667)
владелец
ba3aaa77
Изменения
2
Скрыть пробелы
Построчно
Рядом
ktor-server/ktor-server-core/jvm/src/io/ktor/server/http/content/StaticContent.kt
Просмотр файла @
7f0979ac
...
...
@@ -607,16 +607,21 @@ private fun Route.staticContentRoute(
remotePath
:
String
,
autoHead
:
Boolean
,
handler
:
suspend
(
ApplicationCall
).()
->
Unit
)
=
route
(
remotePath
)
{
route
(
"{$pathParameterName...}"
)
{
get
{
call
.
handler
()
}
if
(
autoHead
)
{
method
(
HttpMethod
.
Head
)
{
install
(
StaticContentAutoHead
)
handle
{
call
.
handler
()
)
=
createChild
(
object
:
RouteSelector
()
{
override
suspend
fun
evaluate
(
context
:
RoutingResolveContext
,
segmentIndex
:
Int
):
RouteSelectorEvaluation
=
RouteSelectorEvaluation
.
Success
(
quality
=
RouteSelectorEvaluation
.
qualityTailcard
)
}).
apply
{
route
(
remotePath
)
{
route
(
"{$pathParameterName...}"
)
{
get
{
call
.
handler
()
}
if
(
autoHead
)
{
method
(
HttpMethod
.
Head
)
{
install
(
StaticContentAutoHead
)
handle
{
call
.
handler
()
}
}
}
}
...
...
ktor-server/ktor-server-plugins/ktor-server-resources/jvm/test/io/ktor/tests/resources/ResourcesTestJvm.kt
Просмотр файла @
7f0979ac
...
...
@@ -4,15 +4,25 @@
package
io.ktor.tests.resources
import
io.ktor.client.request.*
import
io.ktor.client.statement.*
import
io.ktor.http.*
import
io.ktor.resources.*
import
io.ktor.server.http.content.*
import
io.ktor.server.resources.*
import
io.ktor.server.response.*
import
io.ktor.server.routing.*
import
kotlinx.serialization.*
import
kotlinx.serialization.descriptors.*
import
kotlinx.serialization.encoding.*
import
java.math.*
import
kotlin.test.*
import
kotlinx.serialization.KSerializer
import
kotlinx.serialization.Serializable
import
kotlinx.serialization.descriptors.PrimitiveKind
import
kotlinx.serialization.descriptors.PrimitiveSerialDescriptor
import
kotlinx.serialization.descriptors.SerialDescriptor
import
kotlinx.serialization.encoding.Decoder
import
kotlinx.serialization.encoding.Encoder
import
java.math.BigDecimal
import
kotlin.test.Test
import
kotlin.test.assertEquals
import
kotlin.test.assertTrue
class
ResourcesTestJvm
{
...
...
@@ -57,4 +67,25 @@ class ResourcesTestJvm {
"/?bd=123456789012345678901234567890&bi=123456789012345678901234567890"
)
}
@Resource
(
"/"
)
class
Home
@Test
fun
testHomeResourceWithStaticResource
()
=
testResourcesApplication
{
var
executed
=
false
routing
{
get
<
Home
>
{
executed
=
true
call
.
respondText
(
"OK"
)
}
staticResources
(
"/"
,
"static"
)
}
client
.
get
(
"/"
).
let
{
response
->
assertTrue
(
executed
)
assertEquals
(
HttpStatusCode
.
OK
,
response
.
status
)
assertEquals
(
"OK"
,
response
.
bodyAsText
())
}
}
}
Редактирование
Предварительный просмотр
Поддерживает Markdown
0%
Попробовать снова
или
прикрепить новый файл
.
Отмена
You are about to add
0
people
to the discussion. Proceed with caution.
Сначала завершите редактирование этого сообщения!
Отмена
Пожалуйста,
зарегистрируйтесь
или
войдите
чтобы прокомментировать