Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
grassehh opened this issue May 2, 2024 · 2 comments
Labels

Comments

@grassehh
Copy link

grassehh commented May 2, 2024

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

@kasmarian
Copy link
Member

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

@kasmarian
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants