Fix duplicate content-type header bug, add test #12350
Open
+61
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Micronaut adds a second
Content-Typeheader to an HttpResponse when the result of the controller function is aHttpResponse<Flux<String>>(or other nested data type), and the controller explicitly sets the content type on theHttpResponse. This can be demonstrated with the following simple controller:See https://github.com/wfhartford-wordly/micronaut-duplicate-content-type-headers for a full project demonstrating the bug.
Calling this function from curl shows that two content type headers are present in the response.
This PR fixes the bug by changing the
RouteExecutorto call thecontentTypefunction which sets the header rather than theheaderfunction which adds it. I've also included a unit test which verifies the fix.I first encountered this bug in Micronaut version 4.3.8 and have confirmed that it is present in version 4.10.7 and on the 5.0.x branch.