Hi everyone, while I develop something with ktor-c...
# ktor
g
Hi everyone, while I develop something with ktor-client and JsonFeature enabled, I wonder is there any way to allow not only "application/json" but for more content types, like "application/x-json". For now, I forked JsonFeature to my project code and added newly defined content-type, and modified code a bit(attach the code fragments below).
Copy code
// previous code, io.ktor.client.features.json.JsonFeature
// JsonFeature.Feature object, and install function
            scope.requestPipeline.intercept(HttpRequestPipeline.Transform) { payload ->

                context.accept(ContentType.Application.Json)
                if (context.contentType()?.match(ContentType.Application.Json) != true) {
                    return@intercept
                }

                context.headers.remove(HttpHeaders.ContentType)
                proceedWith(feature.serializer.write(payload))
            }
Copy code
// forked code
// defined possible content types inside Feature object,
            private val allowedContentTypes = listOf(
            ContentType.Application.Json,
            ContentType.parse("application/x-json")
        )
            scope.requestPipeline.intercept(HttpRequestPipeline.Transform) { payload ->
                allowedContentTypes.forEach { context.accept(it) }

                if (allowedContentTypes.none { context.contentType()?.match(it) == true })
                    return@intercept

                context.headers.remove(HttpHeaders.ContentType)
                proceedWith(feature.serializer.write(payload))
            }
e
Hi @Gyeongmin Go, there are no such option for now. Probably we should implement it like server
Content-Negotiation
feature.
btw PRs are always welcome 🙂
👍 1
g
Thanks for your fast reply. I'll try PR... if I can...:)