You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When sending requests using Ktor client with the LogbookClient plugin from logbook-ktor-client installed, the Content-Type header is removed from the request.
Another side effect of this issue is that JacksonJsonFieldBodyFilter does not work properly as it checks the content type.
Expected Behavior
The Content-Type header should be preserved when sending the request.
Actual Behavior
The Content-Typeheader is removed from the request.
Possible Fix
There are two places to fix.
The first is in the LogbookClient class itself. This line should return
it
The second place is in the ClientRequest class.
The getHeaders() and getContentType() method should try to respectively append and retrieve the Content-Type header from the OutgoingContent.contentType property when applicable (this one is necessary in order for features like JacksonJsonFieldBodyFilter to work properly).
Example:
Explainations: For some reasons, Ktor removes the Content-Type header from the request object and pushes it into the OutgoingContent.
Thus the Content-Type is lost when Logbook replaces the content with a fresh new one by using ByteArrayContent(content), and the ClientRequest needs to retrieve the information from the OutgoingContent instead of the headers object.
Description
When sending requests using Ktor client with the
LogbookClient
plugin fromlogbook-ktor-client
installed, theContent-Type
header is removed from the request.Another side effect of this issue is that
JacksonJsonFieldBodyFilter
does not work properly as it checks the content type.Expected Behavior
The
Content-Type
header should be preserved when sending the request.Actual Behavior
The
Content-Type
header is removed from the request.Possible Fix
There are two places to fix.
LogbookClient
class itself. This line should returnThe
getHeaders()
andgetContentType()
method should try to respectively append and retrieve theContent-Type
header from the OutgoingContent.contentType property when applicable (this one is necessary in order for features likeJacksonJsonFieldBodyFilter
to work properly).Example:
Explainations: For some reasons, Ktor removes the
Content-Type
header from therequest
object and pushes it into theOutgoingContent
.Thus the
Content-Type
is lost when Logbook replaces the content with a fresh new one by usingByteArrayContent(content)
, and theClientRequest
needs to retrieve the information from theOutgoingContent
instead of theheaders
object.Steps to Reproduce
ClientTest
test inside the zalando-logbook-1821 folderThe test will fail. If you uninstall
LogbookClient
, the test will pass.Context
I was writing integration tests that check that my request contained the
Content-Type: application/json
header and it failed.Your Environment
Ktor 2.3.10
Logbook 3.8.0
The text was updated successfully, but these errors were encountered: