zalando/logbook

ktor-client: response replaces request body

noffke opened this issue · 1 comments

Description

When using logbook-ktor-client together with a custom sink that merges request and response, the request body is always the response body, i.e. response overwrites request. I think this is caused by the State (https://github.com/zalando/logbook/blob/main/logbook-ktor-common/src/main/kotlin/org/zalando/logbook/common/State.kt) subclasses being objects, which makes them a singleton.

Expected Behavior

I expect that at the point of calling the sink, the request contains the request body and the response contains the response body.

Actual Behavior

At the point of calling the sink, the request's body is that of the response.

Possible Fix

Make State subclasses a class that has to be instanciated so that each request and response has their own State instance.

Steps to Reproduce

Please see LogbookClientWithSinkTest in my upcoming PR.

Context

I'm trying to log http requests and responses when using ktor client

Your Environment

Logbook version 3.9.0