Only write non-default charset in MultipartWriterSupport
This commit only writes the 'charset' parameter in the written headers if it is non-default (not UTF-8), since RFC7578 states that the only allowed parameter is 'boundary'. Closes gh-25885
This commit is contained in:
@@ -149,7 +149,9 @@ public class MultipartHttpMessageWriter extends MultipartWriterSupport
|
||||
/**
|
||||
* Set the character set to use for part headers such as
|
||||
* "Content-Disposition" (and its filename parameter).
|
||||
* <p>By default this is set to "UTF-8".
|
||||
* <p>By default this is set to "UTF-8". If changed from this default,
|
||||
* the "Content-Type" header will have a "charset" parameter that specifies
|
||||
* the character set used.
|
||||
*/
|
||||
public void setCharset(Charset charset) {
|
||||
Assert.notNull(charset, "Charset must not be null");
|
||||
|
||||
@@ -102,7 +102,11 @@ public class MultipartWriterSupport extends LoggingCodecSupport {
|
||||
params.putAll(mediaType.getParameters());
|
||||
}
|
||||
params.put("boundary", new String(boundary, StandardCharsets.US_ASCII));
|
||||
params.put("charset", getCharset().name());
|
||||
Charset charset = getCharset();
|
||||
if (!charset.equals(StandardCharsets.UTF_8) &&
|
||||
!charset.equals(StandardCharsets.US_ASCII) ) {
|
||||
params.put("charset", getCharset().name());
|
||||
}
|
||||
|
||||
mediaType = (mediaType != null ? mediaType : MediaType.MULTIPART_FORM_DATA);
|
||||
mediaType = new MediaType(mediaType, params);
|
||||
|
||||
Reference in New Issue
Block a user