Skip to content

Commit

Permalink
Improve performance of FormContentFilter
Browse files Browse the repository at this point in the history
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 spring-projectsgh-23216
  • Loading branch information
philwebb committed Jun 30, 2019
1 parent b3d56eb commit 932f771
Showing 1 changed file with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,17 @@ public InputStream getBody() throws IOException {
}

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;
}


Expand Down

0 comments on commit 932f771

Please sign in to comment.