-
Notifications
You must be signed in to change notification settings - Fork 38.8k
Description
Harald Wellmann opened SPR-8867 and commented
After upgrading my Spring MVC application from Spring 3.0.6 to 3.1.0.RC1, I'm getting errors from some of my AJAX requests with JSON responses.
With Spring 3.0.6, the Content-Length header was not set. With Spring 3.1.0.RC1 the header is set, but the value does not match the actual length of the JSON string, which causes the truncation.
My controller method returns a HttpEntity where the Content-Type header is set to text/plain;charset=utf-8. The problem seems to be that StringHttpMessageConverter uses the charset from the output message for encoding the content in writeInternal(), but does not use the same character set for computing the length: getContentLength() derives the character set from the MediaType and defaults to iso-8559-1. This is why the Content-Length value is smaller than it should be.
Affects: 3.1 RC1
Issue Links:
- Regression: AbstractHttpMessageConverter does not set ContentType [SPR-11685] #16308 Regression: AbstractHttpMessageConverter does not set ContentType
- Allow configuration of whether HttpMessageConverters should set content-length header [SPR-8682] #13324 Allow configuration of whether HttpMessageConverters should set content-length header
Referenced from: commits spring-attic/spring-framework-issues@f9de7ce, spring-attic/spring-framework-issues@1f66876