From 46f051187618e4172ed30c99a2cfece61016ef71 Mon Sep 17 00:00:00 2001 From: JamesHillyard <73830120+JamesHillyard@users.noreply.github.com> Date: Mon, 13 Sep 2021 11:10:42 +0100 Subject: [PATCH 1/2] Merge pull request #31 from JamesHillyard/FISH-376 FISH-376 Allow finer configuration details of HTTP GZIP compression --- .../grizzly/compression/zip/GZipEncoder.java | 11 ++++++- .../grizzly/http/GZipContentEncoding.java | 29 +++++++++++++++---- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/modules/grizzly/src/main/java/org/glassfish/grizzly/compression/zip/GZipEncoder.java b/modules/grizzly/src/main/java/org/glassfish/grizzly/compression/zip/GZipEncoder.java index dca092b84e..a2db37126b 100644 --- a/modules/grizzly/src/main/java/org/glassfish/grizzly/compression/zip/GZipEncoder.java +++ b/modules/grizzly/src/main/java/org/glassfish/grizzly/compression/zip/GZipEncoder.java @@ -43,6 +43,8 @@ public class GZipEncoder extends AbstractTransformer { private static final int TRAILER_SIZE = 8; private final int bufferSize; + private static int compressionLevel; + private static int compressionStrategy; private static final Buffer header; @@ -67,7 +69,13 @@ public GZipEncoder() { } public GZipEncoder(int bufferSize) { + this(bufferSize, Deflater.DEFAULT_COMPRESSION, Deflater.DEFAULT_STRATEGY); + } + + public GZipEncoder(int bufferSize, int compressionLevel, int compressionStrategy) { this.bufferSize = bufferSize; + this.compressionLevel = compressionLevel; + this.compressionStrategy = compressionStrategy; } /** @@ -283,7 +291,8 @@ protected static final class GZipOutputState extends LastResultAwareStateGZipContentEncoding using specific buffer sizes. - * + * Construct GZipContentEncoding using specific buffer sizes, with default compression level and strategy. * @param inBufferSize input buffer size * @param outBufferSize output buffer size - * @param encoderFilter {@link EncodingFilter}, which will decide if GZipContentEncoding should be applied to - * encode specific {@link HttpHeader} packet. + * @param encoderFilter {@link EncodingFilter}, which will decide if + * GZipContentEncoding should be applied to encode specific + * {@link HttpHeader} packet. */ public GZipContentEncoding(int inBufferSize, int outBufferSize, EncodingFilter encoderFilter) { - this.decoder = new GZipDecoder(inBufferSize); - this.encoder = new GZipEncoder(outBufferSize); + this(inBufferSize, outBufferSize, Deflater.DEFAULT_COMPRESSION, Deflater.DEFAULT_STRATEGY, encoderFilter); + } + /** + * Construct GZipContentEncoding using specific buffer sizes, compression level and strategy. + * @param inBufferSize input buffer size + * @param outBufferSize output buffer size + * @param compressionLevel the compression level used by the GZipEncoder + * @param compressionStrategy the compression strategy used by the GZipEncoder + * @param encoderFilter {@link EncodingFilter}, which will decide if + * GZipContentEncoding should be applied to encode specific + * {@link HttpHeader} packet. + */ + public GZipContentEncoding(int inBufferSize, int outBufferSize, int compressionLevel, int compressionStrategy, + EncodingFilter encoderFilter) { + + this.decoder = new GZipDecoder(inBufferSize); + this.encoder = new GZipEncoder(outBufferSize, compressionLevel, compressionStrategy); if (encoderFilter != null) { this.encoderFilter = encoderFilter; } else { From 3ec98e25458def385c1f8f9b51edd24071c95103 Mon Sep 17 00:00:00 2001 From: Matt Gill Date: Mon, 9 Apr 2018 10:34:26 +0100 Subject: [PATCH 2/2] Updated Grizzly version matcher to not match entire pattern. Signed-off-by: Matt Gill --- .../grizzly/src/main/java/org/glassfish/grizzly/Grizzly.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/grizzly/src/main/java/org/glassfish/grizzly/Grizzly.java b/modules/grizzly/src/main/java/org/glassfish/grizzly/Grizzly.java index b6e0010165..8c60c62c14 100644 --- a/modules/grizzly/src/main/java/org/glassfish/grizzly/Grizzly.java +++ b/modules/grizzly/src/main/java/org/glassfish/grizzly/Grizzly.java @@ -66,7 +66,7 @@ public static Logger logger(Class clazz) { } String version = prop.getProperty("grizzly.version"); Matcher matcher = versionPattern.matcher(version); - if (matcher.matches()) { + if (matcher.find()) { dotedVersion = matcher.group(1); major = Integer.parseInt(matcher.group(2)); minor = Integer.parseInt(matcher.group(3));