From 96e09e608c2119f5ea53f61d01149260ef8c480d 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 | 31 ++++++++++++++----- 2 files changed, 34 insertions(+), 8 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. - * + * * @param inBufferSize input buffer size * @param outBufferSize output buffer size */ @@ -59,17 +61,32 @@ public GZipContentEncoding(int inBufferSize, int outBufferSize) { } /** - * Construct GZipContentEncoding 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 90634d9fd9140d1636465d37984293821570d295 Mon Sep 17 00:00:00 2001 From: JamesHillyard Date: Fri, 24 Jun 2022 17:45:12 +0100 Subject: [PATCH 2/2] Review comments --- .../glassfish/grizzly/compression/zip/GZipEncoder.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 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 a2db37126b..49ecbed997 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,8 +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 final int compressionLevel; + private final int compressionStrategy; private static final Buffer header; @@ -112,7 +112,7 @@ protected TransformationResult transformImpl(AttributeStorage st final GZipOutputState state = (GZipOutputState) obtainStateObject(storage); if (!state.isInitialized) { - state.initialize(); + state.initialize(compressionLevel, compressionStrategy); } Buffer encodedBuffer = null; @@ -290,7 +290,7 @@ protected static final class GZipOutputState extends LastResultAwareState