Commit 2448efc0 authored by Stephane Nicoll's avatar Stephane Nicoll

Polish "Cache MimeTypes to improve performance"

Closes gh-16507
parent b3f94c47
/*
* 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));
};
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment