From 2448efc0281e0356de7b1a5ba3e695ef1615d602 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Fri, 19 Apr 2019 16:30:54 +0200 Subject: [PATCH] Polish "Cache MimeTypes to improve performance" Closes gh-16507 --- .../web/embedded/netty/CompressionCustomizer.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) 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 68329f3e10f..807b3861a55 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 @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -65,14 +65,12 @@ final class CompressionCustomizer implements NettyServerCustomizer { return server; } - private CompressionPredicate getMimeTypesPredicate(String[] mimeTypes) { - if (ObjectUtils.isEmpty(mimeTypes)) { + private CompressionPredicate getMimeTypesPredicate(String[] mimeTypeIds) { + if (ObjectUtils.isEmpty(mimeTypeIds)) { return ALWAYS_COMPRESS; } - - List mimeTypeList = Arrays.stream(mimeTypes) + List mimeTypes = Arrays.stream(mimeTypeIds) .map(MimeTypeUtils::parseMimeType).collect(Collectors.toList()); - return (request, response) -> { String contentType = response.responseHeaders() .get(HttpHeaderNames.CONTENT_TYPE); @@ -80,7 +78,7 @@ final class CompressionCustomizer implements NettyServerCustomizer { return false; } MimeType contentMimeType = MimeTypeUtils.parseMimeType(contentType); - return mimeTypeList.stream() + return mimeTypes.stream() .anyMatch((candidate) -> candidate.isCompatibleWith(contentMimeType)); }; }