-
Notifications
You must be signed in to change notification settings - Fork 939
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
Avoid setting default Content-Type in content methods without explicit MediaType #5964
base: main
Are you sure you want to change the base?
Conversation
content(String)
@@ -50,6 +50,7 @@ protected void configure(ServerBuilder sb) { | |||
return HttpResponse.builder() | |||
.ok() | |||
.content("OK\n") | |||
.header(HttpHeaderNames.CONTENT_TYPE, "text/plain; charset=utf-8") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we can simply alter the behavior since it can result in breaking changes like seen in the tests.
Rather, I think a more reasonable approach would be:
- Remember if a
String
content has been set for a request/response - At build time, if a content-type hasn't been set, set
text/plain
as the content-type
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. Will you update the pull request, @JiwonKKang ?
Motivation:
content-type
in response headers #5949HttpResponse could generate duplicate Content-Type headers if a user manually added a Content-Type header after setting the content with content(String). This can cause client errors or unexpected behavior when parsing the response.
Modifications:
Result: