Closed sellmair closed 5 years ago
Hi @sellmair, it looks like the side effect from HttpUrlConnection
: the request type automatically changes to post depends on body configuration.
Could you reproduce it with OkHttp
engine?
I noticed a similar effect which could explain the Exception
, but the post change:
The JsonFeature
only takes into account the Content-Type
of the request, whether it should serialize the payload or not.
If the payload is already instance of OutgoingContent
(like EmptyContent
) this does not make any sense and will fail with the exception above. (see here)
I think it's totally valid to have another guard to check the payload instance here. Something like:
if (payload is OutgoingContent) {
return@intercept
}
Not sure if this solves your problem, I have written the following workaround
class IgnoreOutgoingContentJsonSerializer(private val delegate: JsonSerializer) : JsonSerializer by delegate {
override fun write(data: Any): OutgoingContent {
if (data is OutgoingContent) {
return data
}
return delegate.write(data)
}
}
fun JsonSerializer.ignoreOutgoingContent() = IgnoreOutgoingContentJsonSerializer(this)
val client = HttpClient(OkHttp) {
install(JsonFeature) {
serializer = KotlinxSerializer().ignoreOutgoingContent()
}
}
Ktor Version
1.1.1
Ktor Engine Used(client or server and name)
Netty, Client
JVM Version, Operating System and Relevant Context
Android, Multiplatform
Feedback
Declaration of client
Declaration of request:
Results in
Declaration of request with body
Still sends a post request to the server. Ktor server side logging: