Improve performance of FormContentFilter

Improve the performance of `FormContentFilter` by checking directly if
`contentType` is empty. This saves the need for an exception to thrown
then immediately caught.

Closes gh-23216
This commit is contained in:
Phillip Webb
2019-06-29 22:25:57 -07:00
parent b3d56ebf3b
commit 932f771380

View File

@@ -109,16 +109,17 @@ public class FormContentFilter extends OncePerRequestFilter {
}
private boolean shouldParse(HttpServletRequest request) {
if (!HTTP_METHODS.contains(request.getMethod())) {
return false;
}
try {
MediaType mediaType = MediaType.parseMediaType(request.getContentType());
return MediaType.APPLICATION_FORM_URLENCODED.includes(mediaType);
}
catch (IllegalArgumentException ex) {
return false;
String contentType = request.getContentType();
String method = request.getMethod();
if (StringUtils.hasLength(contentType) && HTTP_METHODS.contains(method)) {
try {
MediaType mediaType = MediaType.parseMediaType(contentType);
return MediaType.APPLICATION_FORM_URLENCODED.includes(mediaType);
}
catch (IllegalArgumentException ex) {
}
}
return false;
}