fix: ContentTypeの判定を修正

This commit is contained in:
usbharu 2023-04-29 15:11:24 +09:00
parent 6ae140a58d
commit b0551ade76
2 changed files with 7 additions and 5 deletions

View File

@ -34,10 +34,10 @@ class ContentTypeRouteSelector(private vararg val contentType: ContentType) : Ro
override fun evaluate(context: RoutingResolveContext, segmentIndex: Int): RouteSelectorEvaluation {
context.call.application.log.debug("Accept: ${context.call.request.accept()}")
val requestContentType =
ContentType.parse(context.call.request.accept() ?: return RouteSelectorEvaluation.FailedParameter)
return if (contentType.find { contentType: ContentType -> contentType.match(requestContentType) } != null) {
val requestContentType = context.call.request.accept() ?: return RouteSelectorEvaluation.FailedParameter
return if (requestContentType.split(",")
.find { contentType.find { contentType -> contentType.match(it) } != null } != null
) {
RouteSelectorEvaluation.Constant
} else {
RouteSelectorEvaluation.FailedParameter

View File

@ -170,9 +170,11 @@ class UsersAPTest {
@Test
// @Disabled
fun contentType_Test() {
assertTrue(ContentType.Application.Activity.match("application/activity+json"))
val listOf = listOf(ContentType.Application.JsonLd, ContentType.Application.Activity)
assertTrue(listOf.find { contentType ->
contentType.match("application/ld+json; profile=\"\\\"https://www.w3.org/ns/activitystreams\\\",application/activity+json\"")
contentType.match("application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"")
}.let { it != null })
assertTrue(ContentType.Application.JsonLd.match("application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\""))
}