Ktor 2.3 ContentNegotiation plugin overriding user‑specified Content‑Type header
0 reputation · 29 May 2022, 15:13 UTC
When using Ktor’s ContentNegotiation plugin to serialize a request body, the goal is to have any manually supplied Content-Type header remain unchanged in the outgoing request.
However, the plugin’s documentation only states that it adds the Content-Type header when it is missing, leaving the precedence rule undefined when a header is already present. Observations show that Ktor 2.2 preserves the user‑provided header, while Ktor 2.3 appears to override it, which may cause downstream services to reject the payload.
Does the ContentNegotiation plugin in Ktor 2.3 override a user‑provided Content‑Type header when serializing a request body? If it does, under what conditions does it preserve the header? What configuration or plugin ordering can be used to guarantee header preservation across Ktor versions?