Gyeongmin Go
03/22/2019, 8:54 AM// 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))
}
// 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))
}
e5l
03/22/2019, 8:56 AMContent-Negotiation
feature.e5l
03/22/2019, 8:56 AMGyeongmin Go
03/22/2019, 8:59 AM