diff --git a/spring-web/src/main/java/org/springframework/http/ContentDisposition.java b/spring-web/src/main/java/org/springframework/http/ContentDisposition.java index 11c381ba68..e8985d81de 100644 --- a/spring-web/src/main/java/org/springframework/http/ContentDisposition.java +++ b/spring-web/src/main/java/org/springframework/http/ContentDisposition.java @@ -27,8 +27,9 @@ import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; -import static java.nio.charset.StandardCharsets.*; -import static java.time.format.DateTimeFormatter.*; +import static java.nio.charset.StandardCharsets.ISO_8859_1; +import static java.nio.charset.StandardCharsets.UTF_8; +import static java.time.format.DateTimeFormatter.RFC_1123_DATE_TIME; /** * Represent the Content-Disposition type and parameters as defined in RFC 2183. @@ -416,8 +417,14 @@ public class ContentDisposition { Builder filename(String filename); /** - * Set the value of the {@literal filename*} that will be encoded as defined in - * the RFC 5987. Only the US-ASCII, UTF-8 and ISO-8859-1 charsets are supported. + * Set the value of the {@literal filename*} that will be encoded as + * defined in the RFC 5987. Only the US-ASCII, UTF-8 and ISO-8859-1 + * charsets are supported. + *
Note: Do not use this for a
+ * {@code "multipart/form-data"} requests as per
+ * RFC 7578, Section 4.2
+ * and also RFC 5987 itself mentions it does not apply to multipart
+ * requests.
*/
Builder filename(String filename, Charset charset);
diff --git a/spring-web/src/main/java/org/springframework/http/HttpHeaders.java b/spring-web/src/main/java/org/springframework/http/HttpHeaders.java
index fb6884f260..5ae97660c2 100644
--- a/spring-web/src/main/java/org/springframework/http/HttpHeaders.java
+++ b/spring-web/src/main/java/org/springframework/http/HttpHeaders.java
@@ -742,48 +742,32 @@ public class HttpHeaders implements MultiValueMap Applications typically would not set this header directly but
+ * rather prepare a {@code MultiValueMap Only the US-ASCII, UTF-8 and ISO-8859-1 charsets are supported.
- * @param name the control name
- * @param filename the filename (may be {@code null})
- * @param charset the charset used for the filename (may be {@code null})
- * @since 4.3.3
- * @see #setContentDisposition(ContentDisposition)
- * @see #getContentDisposition()
- * @see RFC 7230 Section 3.2.4
- */
- public void setContentDispositionFormData(String name, @Nullable String filename, @Nullable Charset charset) {
Assert.notNull(name, "'name' must not be null");
ContentDisposition.Builder disposition = ContentDisposition.builder("form-data").name(name);
if (filename != null) {
- if (charset != null) {
- disposition.filename(filename, charset);
- }
- else {
- disposition.filename(filename);
- }
+ disposition.filename(filename);
}
setContentDisposition(disposition.build());
}
/**
- * Set the (new) value of the {@literal Content-Disposition} header. Supports the
- * disposition type and {@literal filename}, {@literal filename*} (encoded according
- * to RFC 5987, only the US-ASCII, UTF-8 and ISO-8859-1 charsets are supported),
- * {@literal name}, {@literal size} parameters.
+ * Set the {@literal Content-Disposition} header.
+ * This could be used on a response to indicate if the content is
+ * expected to be displayed inline in the browser or as an attachment to be
+ * saved locally.
+ * It can also be used for a {@code "multipart/form-data"} request.
+ * For more details see notes on {@link #setContentDispositionFormData}.
* @since 5.0
* @see #getContentDisposition()
*/
@@ -792,10 +776,7 @@ public class HttpHeaders implements MultiValueMap