zalando/logbook

[logbook-ktor-server] Content-Type header not parsed correctly from the request

grassehh opened this issue · 2 comments

Description

When sending a request having the logbook-ktor-server plugin installed, the Content-Type String value is not correctly retrieved.
An example of a consequence of this is that when configuring a formatter like the JsonHttpLogFormatter, the request body won't be printed as JSON, but plain text instead (with \n characters)

Expected Behavior

The Content-Type header string value should be correct (ex: application/json)

Actual Behavior

The Content-Type header string value is incorrect (ex: application instead of application/json)

Possible Fix

Replace .contentType with .toString() when retrieving the content type String value.

Steps to Reproduce

If you read the request log, the body will look like this:

 "body": "{\n    \"name\": \"John Doe\",\n    \"age\": 25\n}"

If you uncomment the line 28 and test with com.grassehh.logbook.LogbookServer instead, it will be printed correctly:

"body": {
  "name": "John Doe",
  "age": 25
}

Context

I changed my formatter to JsonHttpLogFormatter then in Datadog, I noticed my JSON request body were no longer indexed because it was treated as a plain text instead of an actual JSON.

Your Environment

Ktor 2.3.10
Logbook 3.8.0

@grassehh I opened a PR with the fix as per your suggestion, please take a look: #1834

The fix will be in the next release, thank you for the detailed issue