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 { override fun evaluate(context: RoutingResolveContext, segmentIndex: Int): RouteSelectorEvaluation {
context.call.application.log.debug("Accept: ${context.call.request.accept()}") context.call.application.log.debug("Accept: ${context.call.request.accept()}")
val requestContentType = val requestContentType = context.call.request.accept() ?: return RouteSelectorEvaluation.FailedParameter
ContentType.parse(context.call.request.accept() ?: return RouteSelectorEvaluation.FailedParameter) return if (requestContentType.split(",")
.find { contentType.find { contentType -> contentType.match(it) } != null } != null
return if (contentType.find { contentType: ContentType -> contentType.match(requestContentType) } != null) { ) {
RouteSelectorEvaluation.Constant RouteSelectorEvaluation.Constant
} else { } else {
RouteSelectorEvaluation.FailedParameter RouteSelectorEvaluation.FailedParameter

View File

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