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) {
|
private boolean shouldParse(HttpServletRequest request) {
|
||||||
if (!HTTP_METHODS.contains(request.getMethod())) {
|
String contentType = request.getContentType();
|
||||||
return false;
|
String method = request.getMethod();
|
||||||
}
|
if (StringUtils.hasLength(contentType) && HTTP_METHODS.contains(method)) {
|
||||||
try {
|
try {
|
||||||
MediaType mediaType = MediaType.parseMediaType(request.getContentType());
|
MediaType mediaType = MediaType.parseMediaType(contentType);
|
||||||
return MediaType.APPLICATION_FORM_URLENCODED.includes(mediaType);
|
return MediaType.APPLICATION_FORM_URLENCODED.includes(mediaType);
|
||||||
}
|
}
|
||||||
catch (IllegalArgumentException ex) {
|
catch (IllegalArgumentException ex) {
|
||||||
return false;
|
}
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user