-
Notifications
You must be signed in to change notification settings - Fork 264
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 removes Content-Type header from response #1627
Comments
TLDR: The issue is more general than using the While running the server with a GET endpoint, and sending a GET request, I see this in the logs:
The issue is in a map lookup here (where logbook/logbook-ktor-server/src/main/kotlin/org/zalando/logbook/server/LogbookServer.kt Line 58 in 60314c2
The map was supposed to be filled by the proper value here: logbook/logbook-ktor-server/src/main/kotlin/org/zalando/logbook/server/LogbookServer.kt Line 53 in 60314c2
The above line is executed when intercepting the Receive Pipeline during the logbook/logbook-ktor-server/src/main/kotlin/org/zalando/logbook/server/LogbookServer.kt Line 40 in 60314c2
As per Ktor docs for ApplicationReceivePipeline:
Using a debugger, I noted that this phase is only executed when the request has some content (body). The unit tests also set up the server with POST endpoints: logbook/logbook-ktor-server/src/test/kotlin/org/zalando/logbook/server/LogbookServerTest.kt Lines 62 to 76 in 60314c2
@grassehh Based on the above explanation, do you know how to fix the issue? |
PS: The receive pipeline can be manually triggered by something like this (here, I added data class SomeData(val someProp: String)
route("/test") {
get {
call.receiveText()
call.respond(SomeData("someValue"))
}
} |
Would like to diagnose and fix this issue if its up for grabs |
@adarshjhaa100 Thanks a lot, true open source spirit! |
Thanks for the analysis. Indeed we also did notice this issue for GET routes on our project. The workaround as you mentionned is to manually trigger the pipeline by calling one of the |
Hello, @ChristianLohmann @msdousti, is there any update about the |
Hello, I just noticed the same issue is true for logbook-ktor-client. EDIT: @ChristianLohmann @sokomishalov shouldn't this line return I have also slightly modified the override fun getHeaders(): HttpHeaders = HttpHeaders.of(request.headers.build().toMap())
.also {
if (it.contains(ContentType).not() && request.body is OutgoingContent) return it.update(
ContentType,
(request.body as OutgoingContent).contentType.toString()
)
}
override fun getContentType(): String? =
request.contentType()?.toString()?.substringBefore(";") ?: (request.body as? OutgoingContent)?.contentType?.toString() This way, features like the |
@grassehh: I opened a PR that hopefully addresses the issue with the For the issue you reported with the |
When using
logbook-ktor-server
with Ktor Content Negotation server plugin, theContent-Type
header is not returned in the response.Description
Content Negotation feature for Ktor server automatically detects the
Content-Type
based on the data returned.For instance, configuring it with Jackon as a deserializer allows Ktor server to add the
Content-Type: application/json
header in the response.However, also installing
logbook-ktor-server
result in the header being removed in the response.Expected Behavior
The
Content-Type: application/json
header should be returned in the responseActual Behavior
The
Content-Type
header is missing in the responseSteps to Reproduce
Context
I had some integration tests assertions with RestAssured that failed after adding
logbook-ktor-server
because theContent-Type
header was no longer returned, thus RestAssured is no longer able to parse the response.Your Environment
ktor 2.3.3
logbook 3.4.0
I haven't had time to make a sample yet sorry.
The text was updated successfully, but these errors were encountered: