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:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user