Skip to content

Commit d97eabb

Browse files
committed
Do not cache multipart MIME types in cache
Prior to this commmit, "mutipart/*" MIME types would be cached by the `MimeTypeUtils` LRU cache. Since those MIME types are likely to have random boundaries in them, they can waste space in the LRU cache. This is not improving things since we're parsing them anyway. This commit skips the caching step for all "multipart" MIME types. Fixes gh-24767
1 parent 1cd0e72 commit d97eabb

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

spring-core/src/main/java/org/springframework/util/MimeTypeUtils.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,10 @@ public static MimeType parseMimeType(String mimeType) {
193193
if (!StringUtils.hasLength(mimeType)) {
194194
throw new InvalidMimeTypeException(mimeType, "'mimeType' must not be empty");
195195
}
196+
// do not cache multipart mime types with random boundaries
197+
if (mimeType.startsWith("multipart")) {
198+
return parseMimeTypeInternal(mimeType);
199+
}
196200
return cachedMimeTypes.get(mimeType);
197201
}
198202

0 commit comments

Comments
 (0)