mirror of https://github.com/usbharu/Hideout.git
fix: ContentTypeの判定を修正
This commit is contained in:
parent
6ae140a58d
commit
b0551ade76
|
@ -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
|
||||||
|
|
|
@ -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\""))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue