Polish "Cache MimeTypes to improve performance"

Closes gh-16507
This commit is contained in:
Stephane Nicoll 2019-04-19 16:30:54 +02:00
parent b3f94c47d9
commit 2448efc028
1 changed files with 5 additions and 7 deletions

View File

@ -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<MimeType> mimeTypeList = Arrays.stream(mimeTypes)
List<MimeType> 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));
};
}