Polish "Cache MimeTypes to improve performance"
Closes gh-16507
This commit is contained in:
parent
b3f94c47d9
commit
2448efc028
|
|
@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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;
|
return server;
|
||||||
}
|
}
|
||||||
|
|
||||||
private CompressionPredicate getMimeTypesPredicate(String[] mimeTypes) {
|
private CompressionPredicate getMimeTypesPredicate(String[] mimeTypeIds) {
|
||||||
if (ObjectUtils.isEmpty(mimeTypes)) {
|
if (ObjectUtils.isEmpty(mimeTypeIds)) {
|
||||||
return ALWAYS_COMPRESS;
|
return ALWAYS_COMPRESS;
|
||||||
}
|
}
|
||||||
|
List<MimeType> mimeTypes = Arrays.stream(mimeTypeIds)
|
||||||
List<MimeType> mimeTypeList = Arrays.stream(mimeTypes)
|
|
||||||
.map(MimeTypeUtils::parseMimeType).collect(Collectors.toList());
|
.map(MimeTypeUtils::parseMimeType).collect(Collectors.toList());
|
||||||
|
|
||||||
return (request, response) -> {
|
return (request, response) -> {
|
||||||
String contentType = response.responseHeaders()
|
String contentType = response.responseHeaders()
|
||||||
.get(HttpHeaderNames.CONTENT_TYPE);
|
.get(HttpHeaderNames.CONTENT_TYPE);
|
||||||
|
|
@ -80,7 +78,7 @@ final class CompressionCustomizer implements NettyServerCustomizer {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
MimeType contentMimeType = MimeTypeUtils.parseMimeType(contentType);
|
MimeType contentMimeType = MimeTypeUtils.parseMimeType(contentType);
|
||||||
return mimeTypeList.stream()
|
return mimeTypes.stream()
|
||||||
.anyMatch((candidate) -> candidate.isCompatibleWith(contentMimeType));
|
.anyMatch((candidate) -> candidate.isCompatibleWith(contentMimeType));
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue