From b0551ade761f33aeba8584b71da188cbe5085ad9 Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Sat, 29 Apr 2023 15:11:24 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20ContentType=E3=81=AE=E5=88=A4=E5=AE=9A?= =?UTF-8?q?=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../usbharu/hideout/routing/activitypub/UserRouting.kt | 8 ++++---- .../usbharu/hideout/routing/activitypub/UsersAPTest.kt | 4 +++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/dev/usbharu/hideout/routing/activitypub/UserRouting.kt b/src/main/kotlin/dev/usbharu/hideout/routing/activitypub/UserRouting.kt index 559ca0a0..6212297a 100644 --- a/src/main/kotlin/dev/usbharu/hideout/routing/activitypub/UserRouting.kt +++ b/src/main/kotlin/dev/usbharu/hideout/routing/activitypub/UserRouting.kt @@ -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 diff --git a/src/test/kotlin/dev/usbharu/hideout/routing/activitypub/UsersAPTest.kt b/src/test/kotlin/dev/usbharu/hideout/routing/activitypub/UsersAPTest.kt index 9f713056..0e997f43 100644 --- a/src/test/kotlin/dev/usbharu/hideout/routing/activitypub/UsersAPTest.kt +++ b/src/test/kotlin/dev/usbharu/hideout/routing/activitypub/UsersAPTest.kt @@ -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\"")) }