Avoid duplicate flushes in String Http converter

Prior to this commit, the `StringHttpMessageConverter` would perform a
flush after writing the body, via `StreamUtils#copy`. This operation is
not needed as a flush is already performed by the abstract class.

Flush calls by HTTP message converters is being reconsidered altogether
in gh-35427, but we should first remove this extra operation.

Closes gh-36065
This commit is contained in:
Brian Clozel
2025-12-22 15:34:41 +01:00
parent fc2e1dd2e5
commit fc1ff88ede
@@ -29,7 +29,6 @@ import org.springframework.http.HttpInputMessage;
import org.springframework.http.HttpOutputMessage;
import org.springframework.http.MediaType;
import org.springframework.util.Assert;
import org.springframework.util.StreamUtils;
/**
* Implementation of {@link HttpMessageConverter} that can read and write strings.
@@ -125,7 +124,7 @@ public class StringHttpMessageConverter extends AbstractHttpMessageConverter<Str
headers.setAcceptCharset(getAcceptedCharsets());
}
Charset charset = getContentTypeCharset(headers.getContentType());
StreamUtils.copy(str, charset, outputMessage.getBody());
outputMessage.getBody().write(str.getBytes(charset));
}