Should ServletServerHttpResponse
copy servletResponse
when constructed; otherwise we can't get contentType
when write.
https://github.com/spring-projects/spring-framework/blob/a34f1e375907350cc2dd211f0c8dc59f0e4e1890/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/AbstractMessageConverterMethodProcessor.java#L215-L223
https://github.com/spring-projects/spring-framework/blob/a34f1e375907350cc2dd211f0c8dc59f0e4e1890/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestResponseBodyMethodProcessor.java#L171-L181
https://github.com/spring-projects/spring-framework/blob/a34f1e375907350cc2dd211f0c8dc59f0e4e1890/spring-web/src/main/java/org/springframework/http/server/ServletServerHttpResponse.java#L58-L62
Comment From: sbrannen
Are you saying that the content type from the initial HttpServletResponse
is not taken into account?
Comment From: rstoyanchev
For the headers it creates ServletResponseHttpHeaders
which is essentially an HttpHeaders
with overridden getFirst
and get
methods which access values from the underlying response. So no, it doesn't have to copy them but if there is an issue please provide a sample to demonstrate it.
Comment From: czjxy881
the headers in ServletServerHttpResponse
is the new empty header, so it will lost the header we setted in advice. We want to set content-type in our code to make sure return json. But this can't work because the content type lose when createOutputMessage
Comment From: rstoyanchev
We do support setting the content-type from the controller method. Try returning ResponseEntity
with the headers set.