[Kotlin] fix(#14044): ktor JSON serialization handling (#16843)

This commit is contained in:
Julian Kalinowski
2023-11-08 07:48:43 +01:00
committed by GitHub
parent ced31f49b3
commit f35b132068
9 changed files with 41 additions and 0 deletions

View File

@@ -13,6 +13,7 @@ import io.ktor.client.request.request
import io.ktor.client.request.setBody
import io.ktor.client.statement.HttpResponse
import io.ktor.http.contentType
import io.ktor.http.ContentType
import io.ktor.http.HttpHeaders
import io.ktor.http.HttpMethod
import io.ktor.http.Parameters
@@ -147,6 +148,9 @@ open class ApiClient(
this.method = requestConfig.method.httpMethod
headers.filter { header -> !UNSAFE_HEADERS.contains(header.key) }.forEach { header -> this.header(header.key, header.value) }
if (requestConfig.method in listOf(RequestMethod.PUT, RequestMethod.POST, RequestMethod.PATCH)) {
val contentType = (requestConfig.headers[HttpHeaders.ContentType]?.let { ContentType.parse(it) }
?: ContentType.Application.Json)
this.contentType(contentType)
setBody(body)
}
}