-
Notifications
You must be signed in to change notification settings - Fork 38.4k
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
Content-Type response header duplicated for failed StreamingResponseBody return value #34366
Comments
Thanks for reaching out.
Are you using a specific web server? Another HTTP client? |
I apologize, I should have compared the different web servers beforehand. This is interesting. This happens for jetty, but not for tomcat. Jetty
TomcatTomcat implements special handling for the content type. I'm not sure which handling is expected. I guess the special handling for content type makes sense, but at the same time this isn't clear from the Here is a full spring boot project reproducer with jetty and the |
No worries and thanks for the feedback. I'll have a look. |
I think this is related to several issues. While this looks like a bug and we should in theory fix this in the latest maintenance version (the upcoming 6.2.4), this has some potential for regressions. Did this duplicate header create behavior issues with proxies, browsers or anything else? Did you just happen to notice this while looking at responses? I'm asking this because if there is no strong reason to a maintenance fix, we could consider this in the upcoming 7.0 version. |
We noticed this behavior together with istio. We seem to run into the same issue that was mentioned here: #27887 (comment). Basically, after going through istio, the We workaround this by not setting the content type if an exception happens within |
Spring Boot: 3.4.2
Spring Framework: 6.2.2
When setting
ResponseEntity#contentType
... then the
Content-Type
header is duplicated on the response for a request that fails withinStreamingResponseBody#writeTo
:This might be specific to async requests, like when using
StreamingResponseBody
.When debugging locally, I found that ...
spring-framework/spring-web/src/main/java/org/springframework/http/server/ServletServerHttpResponse.java
Line 113 in 3c4d535
ServletServerHttpResponse
objects that hold the sameHttpServletResponse
. This might be expected, because differentServletServerHttpResponse
objects can hold different header values. However, this leads to the content type being duplicated.The two
ServletServerHttpResponse
are created at:spring-framework/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/StreamingResponseBodyReturnValueHandler.java
Line 72 in 3c4d535
spring-framework/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/AbstractMessageConverterMethodProcessor.java
Line 164 in 3c4d535
spring-framework/spring-webmvc/src/main/java/org/springframework/web/servlet/DispatcherServlet.java
Line 1206 in 3c4d535
Removing the content type at either of the places has a downside:
Is the duplication of content-type expected here?
Please let me know if more info is required. Thank you in advance, any help is appreciated!
Reproducer:
The text was updated successfully, but these errors were encountered: