use of org.glassfish.grizzly.http.server.CompressionLevel in project Payara by payara.
the class GenericGrizzlyListener method configureCompressionEncodings.
protected Set<ContentEncoding> configureCompressionEncodings(Http http) {
final String mode = http.getCompression();
int compressionMinSize = Integer.parseInt(http.getCompressionMinSizeBytes());
CompressionLevel compressionLevel;
try {
compressionLevel = CompressionLevel.getCompressionLevel(mode);
} catch (IllegalArgumentException e) {
try {
// Try to parse compression as an int, which would give the
// minimum compression size
compressionLevel = CompressionLevel.ON;
compressionMinSize = Integer.parseInt(mode);
} catch (Exception ignore) {
compressionLevel = CompressionLevel.OFF;
}
}
final String compressableMimeTypesString = http.getCompressableMimeType();
final String noCompressionUserAgentsString = http.getNoCompressionUserAgents();
final String[] compressableMimeTypes = ((compressableMimeTypesString != null) ? compressableMimeTypesString.split(",") : new String[0]);
final String[] noCompressionUserAgents = ((noCompressionUserAgentsString != null) ? noCompressionUserAgentsString.split(",") : new String[0]);
final ContentEncoding gzipContentEncoding = new GZipContentEncoding(GZipContentEncoding.DEFAULT_IN_BUFFER_SIZE, GZipContentEncoding.DEFAULT_OUT_BUFFER_SIZE, new CompressionEncodingFilter(compressionLevel, compressionMinSize, compressableMimeTypes, noCompressionUserAgents, GZipContentEncoding.getGzipAliases(), compressionLevel != CompressionLevel.OFF));
final ContentEncoding lzmaEncoding = new LZMAContentEncoding(new CompressionEncodingFilter(compressionLevel, compressionMinSize, compressableMimeTypes, noCompressionUserAgents, LZMAContentEncoding.getLzmaAliases(), compressionLevel != CompressionLevel.OFF));
final Set<ContentEncoding> set = new HashSet<ContentEncoding>(2);
set.add(gzipContentEncoding);
set.add(lzmaEncoding);
return set;
}
Aggregations