diff --git a/spring-web/src/main/java/org/springframework/http/converter/FormHttpMessageConverter.java b/spring-web/src/main/java/org/springframework/http/converter/FormHttpMessageConverter.java
index d5208627d1..e39b6e13ce 100644
--- a/spring-web/src/main/java/org/springframework/http/converter/FormHttpMessageConverter.java
+++ b/spring-web/src/main/java/org/springframework/http/converter/FormHttpMessageConverter.java
@@ -51,14 +51,14 @@ import org.springframework.util.StringUtils;
*
*
In other words, this converter can read and write the
* {@code "application/x-www-form-urlencoded"} media type as
- * {@link MultiValueMap MultiValueMap<String, String>} and it can also
+ * {@link MultiValueMap MultiValueMap<String, String>}, and it can also
* write (but not read) the {@code "multipart/form-data"} media type as
* {@link MultiValueMap MultiValueMap<String, Object>}.
*
*
When writing multipart data, this converter uses other
* {@link HttpMessageConverter HttpMessageConverters} to write the respective
- * MIME parts. By default, basic converters are registered (for {@code Strings}
- * and {@code Resources}). These can be overridden through the
+ * MIME parts. By default, basic converters are registered (e.g., for {@code String}
+ * and {@code Resource}). These can be overridden through the
* {@link #setPartConverters partConverters} property.
*
*
For example, the following snippet shows how to submit an HTML form:
@@ -157,14 +157,15 @@ public class FormHttpMessageConverter implements HttpMessageConverterAs of 4.3, this is also used as the default charset for the conversion
* of text bodies in a multipart request.
- * As of 5.0 this is also used for part headers including
- * "Content-Disposition" (and its filename parameter) unless (the mutually
- * exclusive) {@link #setMultipartCharset} is also set, in which case part
- * headers are encoded as ASCII and filename is encoded with the
- * "encoded-word" syntax from RFC 2047.
+ *
As of 5.0, this is also used for part headers including
+ * {@code Content-Disposition} (and its filename parameter) unless (the mutually
+ * exclusive) {@link #setMultipartCharset multipartCharset} is also set, in
+ * which case part headers are encoded as ASCII and filename is encoded
+ * with the {@code encoded-word} syntax from RFC 2047.
*
By default this is set to "UTF-8".
*/
public void setCharset(@Nullable Charset charset) {
@@ -191,10 +192,10 @@ public class FormHttpMessageConverter implements HttpMessageConverterAs of 5.0 by default part headers, including Content-Disposition (and
- * its filename parameter) will be encoded based on the setting of
+ * names. Encoding is based on the {@code encoded-word} syntax defined in
+ * RFC 2047 and relies on {@code MimeUtility} from {@code javax.mail}.
+ * As of 5.0 by default part headers, including {@code Content-Disposition}
+ * (and its filename parameter) will be encoded based on the setting of
* {@link #setCharset(Charset)} or {@code UTF-8} by default.
* @since 4.1.1
* @see Encoded-Word
@@ -374,8 +375,8 @@ public class FormHttpMessageConverter implements HttpMessageConverter 0).as("Invalid request content-length").isTrue();
+ assertThat(Integer.parseInt(request.getHeader("Content-Length"))).as("Invalid request content-length").isGreaterThan(0);
String requestContentType = request.getHeader("Content-Type");
assertThat(requestContentType).as("No content-type").isNotNull();
Charset charset = StandardCharsets.ISO_8859_1;
@@ -106,7 +106,7 @@ public class AbstractMockWebServerTestCase {
private MockResponse jsonPostRequest(RecordedRequest request, String location, String contentType) {
if (request.getBodySize() > 0) {
- assertThat(Integer.parseInt(request.getHeader("Content-Length")) > 0).as("Invalid request content-length").isTrue();
+ assertThat(Integer.parseInt(request.getHeader("Content-Length"))).as("Invalid request content-length").isGreaterThan(0);
assertThat(request.getHeader("Content-Type")).as("No content-type").isNotNull();
}
return new MockResponse()
@@ -137,27 +137,27 @@ public class AbstractMockWebServerTestCase {
private void assertPart(Buffer buffer, String disposition, String boundary, String name,
String contentType, String value) throws EOFException {
- assertThat(buffer.readUtf8Line().contains("--" + boundary)).isTrue();
+ assertThat(buffer.readUtf8Line()).contains("--" + boundary);
String line = buffer.readUtf8Line();
- assertThat(line.contains("Content-Disposition: "+ disposition)).isTrue();
- assertThat(line.contains("name=\""+ name + "\"")).isTrue();
- assertThat(buffer.readUtf8Line().startsWith("Content-Type: "+contentType)).isTrue();
- assertThat(buffer.readUtf8Line().equals("Content-Length: " + value.length())).isTrue();
- assertThat(buffer.readUtf8Line().equals("")).isTrue();
- assertThat(buffer.readUtf8Line().equals(value)).isTrue();
+ assertThat(line).contains("Content-Disposition: "+ disposition);
+ assertThat(line).contains("name=\""+ name + "\"");
+ assertThat(buffer.readUtf8Line()).startsWith("Content-Type: "+contentType);
+ assertThat(buffer.readUtf8Line()).isEqualTo("Content-Length: " + value.length());
+ assertThat(buffer.readUtf8Line()).isEqualTo("");
+ assertThat(buffer.readUtf8Line()).isEqualTo(value);
}
private void assertFilePart(Buffer buffer, String disposition, String boundary, String name,
String filename, String contentType) throws EOFException {
- assertThat(buffer.readUtf8Line().contains("--" + boundary)).isTrue();
+ assertThat(buffer.readUtf8Line()).contains("--" + boundary);
String line = buffer.readUtf8Line();
- assertThat(line.contains("Content-Disposition: "+ disposition)).isTrue();
- assertThat(line.contains("name=\""+ name + "\"")).isTrue();
- assertThat(line.contains("filename=\""+ filename + "\"")).isTrue();
- assertThat(buffer.readUtf8Line().startsWith("Content-Type: "+contentType)).isTrue();
- assertThat(buffer.readUtf8Line().startsWith("Content-Length: ")).isTrue();
- assertThat(buffer.readUtf8Line().equals("")).isTrue();
+ assertThat(line).contains("Content-Disposition: " + disposition);
+ assertThat(line).contains("name=\"" + name + "\"");
+ assertThat(line).contains("filename=\"" + filename + "\"");
+ assertThat(buffer.readUtf8Line()).startsWith("Content-Type: " + contentType);
+ assertThat(buffer.readUtf8Line()).startsWith("Content-Length: ");
+ assertThat(buffer.readUtf8Line()).isEqualTo("");
assertThat(buffer.readUtf8Line()).isNotNull();
}
@@ -174,7 +174,7 @@ public class AbstractMockWebServerTestCase {
String contentType, byte[] responseBody) {
assertThat(request.getMethod()).isEqualTo("PATCH");
- assertThat(Integer.parseInt(request.getHeader("Content-Length")) > 0).as("Invalid request content-length").isTrue();
+ assertThat(Integer.parseInt(request.getHeader("Content-Length"))).as("Invalid request content-length").isGreaterThan(0);
String requestContentType = request.getHeader("Content-Type");
assertThat(requestContentType).as("No content-type").isNotNull();
Charset charset = StandardCharsets.ISO_8859_1;
@@ -192,7 +192,7 @@ public class AbstractMockWebServerTestCase {
}
private MockResponse putRequest(RecordedRequest request, String expectedRequestContent) {
- assertThat(Integer.parseInt(request.getHeader("Content-Length")) > 0).as("Invalid request content-length").isTrue();
+ assertThat(Integer.parseInt(request.getHeader("Content-Length"))).as("Invalid request content-length").isGreaterThan(0);
String requestContentType = request.getHeader("Content-Type");
assertThat(requestContentType).as("No content-type").isNotNull();
Charset charset = StandardCharsets.ISO_8859_1;