Browse Source

Use MediaType.APPLICATION_FORM_URLENCODED_VALUE

See gh-28771
pull/28959/head
Johnny Lim 4 years ago committed by Rossen Stoyanchev
parent
commit
00f7f5ff0a
  1. 2
      spring-web/src/main/java/org/springframework/http/server/ServletServerHttpRequest.java
  2. 6
      spring-web/src/main/java/org/springframework/web/util/ContentCachingRequestWrapper.java
  3. 3
      spring-webmvc/src/main/java/org/springframework/web/servlet/DispatcherServlet.java

2
spring-web/src/main/java/org/springframework/http/server/ServletServerHttpRequest.java

@ -56,7 +56,7 @@ import org.springframework.util.StringUtils; @@ -56,7 +56,7 @@ import org.springframework.util.StringUtils;
*/
public class ServletServerHttpRequest implements ServerHttpRequest {
protected static final String FORM_CONTENT_TYPE = "application/x-www-form-urlencoded";
protected static final String FORM_CONTENT_TYPE = MediaType.APPLICATION_FORM_URLENCODED_VALUE;
protected static final Charset FORM_CHARSET = StandardCharsets.UTF_8;

6
spring-web/src/main/java/org/springframework/web/util/ContentCachingRequestWrapper.java

@ -33,6 +33,7 @@ import javax.servlet.http.HttpServletRequest; @@ -33,6 +33,7 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.lang.Nullable;
/**
@ -55,9 +56,6 @@ import org.springframework.lang.Nullable; @@ -55,9 +56,6 @@ import org.springframework.lang.Nullable;
*/
public class ContentCachingRequestWrapper extends HttpServletRequestWrapper {
private static final String FORM_CONTENT_TYPE = "application/x-www-form-urlencoded";
private final ByteArrayOutputStream cachedContent;
@Nullable
@ -152,7 +150,7 @@ public class ContentCachingRequestWrapper extends HttpServletRequestWrapper { @@ -152,7 +150,7 @@ public class ContentCachingRequestWrapper extends HttpServletRequestWrapper {
private boolean isFormPost() {
String contentType = getContentType();
return (contentType != null && contentType.contains(FORM_CONTENT_TYPE) &&
return (contentType != null && contentType.contains(MediaType.APPLICATION_FORM_URLENCODED_VALUE) &&
HttpMethod.POST.matches(getMethod()));
}

3
spring-webmvc/src/main/java/org/springframework/web/servlet/DispatcherServlet.java

@ -50,6 +50,7 @@ import org.springframework.core.io.ClassPathResource; @@ -50,6 +50,7 @@ import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.support.PropertiesLoaderUtils;
import org.springframework.core.log.LogFormatUtils;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.server.RequestPath;
import org.springframework.http.server.ServletServerHttpRequest;
import org.springframework.lang.Nullable;
@ -989,7 +990,7 @@ public class DispatcherServlet extends FrameworkServlet { @@ -989,7 +990,7 @@ public class DispatcherServlet extends FrameworkServlet {
}
else {
// Avoid request body parsing for form data
params = (StringUtils.startsWithIgnoreCase(contentType, "application/x-www-form-urlencoded") ||
params = (StringUtils.startsWithIgnoreCase(contentType, MediaType.APPLICATION_FORM_URLENCODED_VALUE) ||
!request.getParameterMap().isEmpty() ? "masked" : "");
}

Loading…
Cancel
Save