diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/netty/CompressionCustomizer.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/netty/CompressionCustomizer.java index a31c3c7a7d..68329f3e10 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/netty/CompressionCustomizer.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/netty/CompressionCustomizer.java @@ -17,7 +17,9 @@ package org.springframework.boot.web.embedded.netty; import java.util.Arrays; +import java.util.List; import java.util.function.BiPredicate; +import java.util.stream.Collectors; import io.netty.handler.codec.http.HttpHeaderNames; import io.netty.handler.codec.http.HttpHeaders; @@ -67,6 +69,10 @@ final class CompressionCustomizer implements NettyServerCustomizer { if (ObjectUtils.isEmpty(mimeTypes)) { return ALWAYS_COMPRESS; } + + List mimeTypeList = Arrays.stream(mimeTypes) + .map(MimeTypeUtils::parseMimeType).collect(Collectors.toList()); + return (request, response) -> { String contentType = response.responseHeaders() .get(HttpHeaderNames.CONTENT_TYPE); @@ -74,7 +80,7 @@ final class CompressionCustomizer implements NettyServerCustomizer { return false; } MimeType contentMimeType = MimeTypeUtils.parseMimeType(contentType); - return Arrays.stream(mimeTypes).map(MimeTypeUtils::parseMimeType) + return mimeTypeList.stream() .anyMatch((candidate) -> candidate.isCompatibleWith(contentMimeType)); }; }