diff --git a/build-spring-framework/resources/changelog.txt b/build-spring-framework/resources/changelog.txt
index 2f26e25106..44aec70917 100644
--- a/build-spring-framework/resources/changelog.txt
+++ b/build-spring-framework/resources/changelog.txt
@@ -23,10 +23,11 @@ Changes in version 3.1 RC2 (2011-11-15)
* added ignoreDefaultModelOnRedirect attribute to
* added methods to UriComponentsBuilder for replacing the path or the query
* added ServletUriComponentsBuilder to build a UriComponents instance starting with a ServletRequest
-* support UriComponentsBuilder as @Controller method argument
+* added support for UriComponentsBuilder as @Controller method argument
* MockHttpServletRequest and MockHttpServletResponse now keep contentType field and Content-Type header in sync
* fixed issue with cache ignoring prototype-scoped controllers in RequestMappingHandlerAdapter
-* update Spring MVC configuration section to include MVC Java config and the MVC namespace
+* updated Spring MVC configuration section to include MVC Java config and the MVC namespace
+* fixed issue with setting Content-Length header depending on the charset of the response
Changes in version 3.1 RC1 (2011-10-11)
---------------------------------------
diff --git a/org.springframework.web/src/main/java/org/springframework/http/converter/AbstractHttpMessageConverter.java b/org.springframework.web/src/main/java/org/springframework/http/converter/AbstractHttpMessageConverter.java
index 6d3356973c..b55b3598b9 100644
--- a/org.springframework.web/src/main/java/org/springframework/http/converter/AbstractHttpMessageConverter.java
+++ b/org.springframework.web/src/main/java/org/springframework/http/converter/AbstractHttpMessageConverter.java
@@ -173,7 +173,7 @@ public abstract class AbstractHttpMessageConverter implements HttpMessageConv
}
}
if (headers.getContentLength() == -1) {
- Long contentLength = getContentLength(t, contentType);
+ Long contentLength = getContentLength(t, headers.getContentType());
if (contentLength != null) {
headers.setContentLength(contentLength);
}
diff --git a/org.springframework.web/src/test/java/org/springframework/http/converter/StringHttpMessageConverterTests.java b/org.springframework.web/src/test/java/org/springframework/http/converter/StringHttpMessageConverterTests.java
index f605b2c1fe..149a84f659 100644
--- a/org.springframework.web/src/test/java/org/springframework/http/converter/StringHttpMessageConverterTests.java
+++ b/org.springframework.web/src/test/java/org/springframework/http/converter/StringHttpMessageConverterTests.java
@@ -85,4 +85,22 @@ public class StringHttpMessageConverterTests {
outputMessage.getHeaders().getContentLength());
assertFalse("Invalid accept-charset", outputMessage.getHeaders().getAcceptCharset().isEmpty());
}
+
+ // SPR-8867
+
+ @Test
+ public void writeOverrideRequestedContentType() throws IOException {
+ Charset utf8 = Charset.forName("UTF-8");
+ MediaType requestedContentType = new MediaType("text", "html");
+ MockHttpOutputMessage outputMessage = new MockHttpOutputMessage();
+ MediaType contentType = new MediaType("text", "plain", utf8);
+ outputMessage.getHeaders().setContentType(contentType);
+ String body = "H\u00e9llo W\u00f6rld";
+ converter.write(body, requestedContentType, outputMessage);
+ assertEquals("Invalid result", body, outputMessage.getBodyAsString(utf8));
+ assertEquals("Invalid content-type", contentType, outputMessage.getHeaders().getContentType());
+ assertEquals("Invalid content-length", body.getBytes(utf8).length,
+ outputMessage.getHeaders().getContentLength());
+ assertFalse("Invalid accept-charset", outputMessage.getHeaders().getAcceptCharset().isEmpty());
+ }
}