Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
openSUSE:Leap:15.5:Update
netty
0004-Disable-Brotli-and-ZStd-compression.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 0004-Disable-Brotli-and-ZStd-compression.patch of Package netty
From d4347c276254ada7a0a06c0d3c0eeb550e9683b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fridrich=20=C5=A0trba?= <fridrich.strba@bluewin.ch> Date: Thu, 30 Mar 2023 13:19:04 +0200 Subject: [PATCH 4/7] Disable Brotli and ZStd compression --- .../codec/http/HttpContentCompressor.java | 105 +----------------- .../codec/http/HttpContentDecompressor.java | 7 -- .../CompressorHttp2ConnectionEncoder.java | 44 +------- .../DelegatingDecompressorFrameListener.java | 13 --- .../StandardCompressionOptions.java | 53 +-------- 5 files changed, 6 insertions(+), 216 deletions(-) diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/HttpContentCompressor.java b/codec-http/src/main/java/io/netty/handler/codec/http/HttpContentCompressor.java index 0effd37779..51e6c10934 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/HttpContentCompressor.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/HttpContentCompressor.java @@ -22,9 +22,6 @@ import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.embedded.EmbeddedChannel; import io.netty.handler.codec.MessageToByteEncoder; -import io.netty.handler.codec.compression.Brotli; -import io.netty.handler.codec.compression.BrotliEncoder; -import io.netty.handler.codec.compression.BrotliOptions; import io.netty.handler.codec.compression.CompressionOptions; import io.netty.handler.codec.compression.DeflateOptions; import io.netty.handler.codec.compression.GzipOptions; @@ -32,11 +29,6 @@ import io.netty.handler.codec.compression.StandardCompressionOptions; import io.netty.handler.codec.compression.ZlibCodecFactory; import io.netty.handler.codec.compression.ZlibEncoder; import io.netty.handler.codec.compression.ZlibWrapper; -import io.netty.handler.codec.compression.Zstd; -import io.netty.handler.codec.compression.ZstdEncoder; -import io.netty.handler.codec.compression.ZstdOptions; -import io.netty.handler.codec.compression.SnappyFrameEncoder; -import io.netty.handler.codec.compression.SnappyOptions; import io.netty.util.internal.ObjectUtil; /** @@ -49,11 +41,8 @@ import io.netty.util.internal.ObjectUtil; public class HttpContentCompressor extends HttpContentEncoder { private final boolean supportsCompressionOptions; - private final BrotliOptions brotliOptions; private final GzipOptions gzipOptions; private final DeflateOptions deflateOptions; - private final ZstdOptions zstdOptions; - private final SnappyOptions snappyOptions; private final int compressionLevel; private final int windowBits; @@ -137,11 +126,8 @@ public class HttpContentCompressor extends HttpContentEncoder { this.windowBits = ObjectUtil.checkInRange(windowBits, 9, 15, "windowBits"); this.memLevel = ObjectUtil.checkInRange(memLevel, 1, 9, "memLevel"); this.contentSizeThreshold = ObjectUtil.checkPositiveOrZero(contentSizeThreshold, "contentSizeThreshold"); - this.brotliOptions = null; this.gzipOptions = null; this.deflateOptions = null; - this.zstdOptions = null; - this.snappyOptions = null; this.factories = null; this.supportsCompressionOptions = false; } @@ -170,17 +156,11 @@ public class HttpContentCompressor extends HttpContentEncoder { */ public HttpContentCompressor(int contentSizeThreshold, CompressionOptions... compressionOptions) { this.contentSizeThreshold = ObjectUtil.checkPositiveOrZero(contentSizeThreshold, "contentSizeThreshold"); - BrotliOptions brotliOptions = null; GzipOptions gzipOptions = null; DeflateOptions deflateOptions = null; - ZstdOptions zstdOptions = null; - SnappyOptions snappyOptions = null; if (compressionOptions == null || compressionOptions.length == 0) { - brotliOptions = Brotli.isAvailable() ? StandardCompressionOptions.brotli() : null; gzipOptions = StandardCompressionOptions.gzip(); deflateOptions = StandardCompressionOptions.deflate(); - zstdOptions = Zstd.isAvailable() ? StandardCompressionOptions.zstd() : null; - snappyOptions = StandardCompressionOptions.snappy(); } else { ObjectUtil.deepCheckNotNull("compressionOptions", compressionOptions); for (CompressionOptions compressionOption : compressionOptions) { @@ -190,16 +170,10 @@ public class HttpContentCompressor extends HttpContentEncoder { // This results in the static analysis of native-image identifying the instanceof BrotliOptions check // and thus BrotliOptions itself as unreachable, enabling native-image to link all classes // at build time and not complain about the missing Brotli classes. - if (Brotli.isAvailable() && compressionOption instanceof BrotliOptions) { - brotliOptions = (BrotliOptions) compressionOption; - } else if (compressionOption instanceof GzipOptions) { + if (compressionOption instanceof GzipOptions) { gzipOptions = (GzipOptions) compressionOption; } else if (compressionOption instanceof DeflateOptions) { deflateOptions = (DeflateOptions) compressionOption; - } else if (compressionOption instanceof ZstdOptions) { - zstdOptions = (ZstdOptions) compressionOption; - } else if (compressionOption instanceof SnappyOptions) { - snappyOptions = (SnappyOptions) compressionOption; } else { throw new IllegalArgumentException("Unsupported " + CompressionOptions.class.getSimpleName() + ": " + compressionOption); @@ -209,9 +183,6 @@ public class HttpContentCompressor extends HttpContentEncoder { this.gzipOptions = gzipOptions; this.deflateOptions = deflateOptions; - this.brotliOptions = brotliOptions; - this.zstdOptions = zstdOptions; - this.snappyOptions = snappyOptions; this.factories = new HashMap<String, CompressionEncoderFactory>(); @@ -221,15 +192,6 @@ public class HttpContentCompressor extends HttpContentEncoder { if (this.deflateOptions != null) { this.factories.put("deflate", new DeflateEncoderFactory()); } - if (Brotli.isAvailable() && this.brotliOptions != null) { - this.factories.put("br", new BrEncoderFactory()); - } - if (this.zstdOptions != null) { - this.factories.put("zstd", new ZstdEncoderFactory()); - } - if (this.snappyOptions != null) { - this.factories.put("snappy", new SnappyEncoderFactory()); - } this.compressionLevel = -1; this.windowBits = -1; @@ -302,9 +264,6 @@ public class HttpContentCompressor extends HttpContentEncoder { @SuppressWarnings("FloatingPointEquality") protected String determineEncoding(String acceptEncoding) { float starQ = -1.0f; - float brQ = -1.0f; - float zstdQ = -1.0f; - float snappyQ = -1.0f; float gzipQ = -1.0f; float deflateQ = -1.0f; for (String encoding : acceptEncoding.split(",")) { @@ -320,41 +279,20 @@ public class HttpContentCompressor extends HttpContentEncoder { } if (encoding.contains("*")) { starQ = q; - } else if (encoding.contains("br") && q > brQ) { - brQ = q; - } else if (encoding.contains("zstd") && q > zstdQ) { - zstdQ = q; - } else if (encoding.contains("snappy") && q > snappyQ) { - snappyQ = q; } else if (encoding.contains("gzip") && q > gzipQ) { gzipQ = q; } else if (encoding.contains("deflate") && q > deflateQ) { deflateQ = q; } } - if (brQ > 0.0f || zstdQ > 0.0f || snappyQ > 0.0f || gzipQ > 0.0f || deflateQ > 0.0f) { - if (brQ != -1.0f && brQ >= zstdQ && this.brotliOptions != null) { - return "br"; - } else if (zstdQ != -1.0f && zstdQ >= snappyQ && this.zstdOptions != null) { - return "zstd"; - } else if (snappyQ != -1.0f && snappyQ >= gzipQ && this.snappyOptions != null) { - return "snappy"; - } else if (gzipQ != -1.0f && gzipQ >= deflateQ && this.gzipOptions != null) { + if (gzipQ > 0.0f || deflateQ > 0.0f) { + if (gzipQ != -1.0f && gzipQ >= deflateQ && this.gzipOptions != null) { return "gzip"; } else if (deflateQ != -1.0f && this.deflateOptions != null) { return "deflate"; } } if (starQ > 0.0f) { - if (brQ == -1.0f && this.brotliOptions != null) { - return "br"; - } - if (zstdQ == -1.0f && this.zstdOptions != null) { - return "zstd"; - } - if (snappyQ == -1.0f && this.snappyOptions != null) { - return "snappy"; - } if (gzipQ == -1.0f && this.gzipOptions != null) { return "gzip"; } @@ -435,41 +373,4 @@ public class HttpContentCompressor extends HttpContentEncoder { deflateOptions.windowBits(), deflateOptions.memLevel()); } } - - /** - * Compression Encoder Factory that creates {@link BrotliEncoder}s - * used to compress http content for br content encoding - */ - private final class BrEncoderFactory implements CompressionEncoderFactory { - - @Override - public MessageToByteEncoder<ByteBuf> createEncoder() { - return new BrotliEncoder(brotliOptions.parameters()); - } - } - - /** - * Compression Encoder Factory for create {@link ZstdEncoder} - * used to compress http content for zstd content encoding - */ - private final class ZstdEncoderFactory implements CompressionEncoderFactory { - - @Override - public MessageToByteEncoder<ByteBuf> createEncoder() { - return new ZstdEncoder(zstdOptions.compressionLevel(), - zstdOptions.blockSize(), zstdOptions.maxEncodeSize()); - } - } - - /** - * Compression Encoder Factory for create {@link SnappyFrameEncoder} - * used to compress http content for snappy content encoding - */ - private static final class SnappyEncoderFactory implements CompressionEncoderFactory { - - @Override - public MessageToByteEncoder<ByteBuf> createEncoder() { - return new SnappyFrameEncoder(); - } - } } diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/HttpContentDecompressor.java b/codec-http/src/main/java/io/netty/handler/codec/http/HttpContentDecompressor.java index e8e1d90972..15f56aff91 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/HttpContentDecompressor.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/HttpContentDecompressor.java @@ -15,7 +15,6 @@ */ package io.netty.handler.codec.http; -import static io.netty.handler.codec.http.HttpHeaderValues.BR; import static io.netty.handler.codec.http.HttpHeaderValues.DEFLATE; import static io.netty.handler.codec.http.HttpHeaderValues.GZIP; import static io.netty.handler.codec.http.HttpHeaderValues.X_DEFLATE; @@ -23,8 +22,6 @@ import static io.netty.handler.codec.http.HttpHeaderValues.X_GZIP; import static io.netty.handler.codec.http.HttpHeaderValues.SNAPPY; import io.netty.channel.embedded.EmbeddedChannel; -import io.netty.handler.codec.compression.Brotli; -import io.netty.handler.codec.compression.BrotliDecoder; import io.netty.handler.codec.compression.ZlibCodecFactory; import io.netty.handler.codec.compression.ZlibWrapper; import io.netty.handler.codec.compression.SnappyFrameDecoder; @@ -69,10 +66,6 @@ public class HttpContentDecompressor extends HttpContentDecoder { return new EmbeddedChannel(ctx.channel().id(), ctx.channel().metadata().hasDisconnect(), ctx.channel().config(), ZlibCodecFactory.newZlibDecoder(wrapper)); } - if (Brotli.isAvailable() && BR.contentEqualsIgnoreCase(contentEncoding)) { - return new EmbeddedChannel(ctx.channel().id(), ctx.channel().metadata().hasDisconnect(), - ctx.channel().config(), new BrotliDecoder()); - } if (SNAPPY.contentEqualsIgnoreCase(contentEncoding)) { return new EmbeddedChannel(ctx.channel().id(), ctx.channel().metadata().hasDisconnect(), diff --git a/codec-http2/src/main/java/io/netty/handler/codec/http2/CompressorHttp2ConnectionEncoder.java b/codec-http2/src/main/java/io/netty/handler/codec/http2/CompressorHttp2ConnectionEncoder.java index 262c8ad18b..150c1929b8 100644 --- a/codec-http2/src/main/java/io/netty/handler/codec/http2/CompressorHttp2ConnectionEncoder.java +++ b/codec-http2/src/main/java/io/netty/handler/codec/http2/CompressorHttp2ConnectionEncoder.java @@ -21,33 +21,23 @@ import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelPromise; import io.netty.channel.embedded.EmbeddedChannel; import io.netty.handler.codec.ByteToMessageDecoder; -import io.netty.handler.codec.compression.BrotliEncoder; import io.netty.handler.codec.compression.ZlibCodecFactory; import io.netty.handler.codec.compression.ZlibWrapper; -import io.netty.handler.codec.compression.Brotli; -import io.netty.handler.codec.compression.BrotliOptions; import io.netty.handler.codec.compression.CompressionOptions; import io.netty.handler.codec.compression.DeflateOptions; import io.netty.handler.codec.compression.GzipOptions; import io.netty.handler.codec.compression.StandardCompressionOptions; -import io.netty.handler.codec.compression.ZstdEncoder; -import io.netty.handler.codec.compression.ZstdOptions; -import io.netty.handler.codec.compression.SnappyFrameEncoder; -import io.netty.handler.codec.compression.SnappyOptions; import io.netty.util.concurrent.PromiseCombiner; import io.netty.util.internal.ObjectUtil; import io.netty.util.internal.UnstableApi; import static io.netty.handler.codec.http.HttpHeaderNames.CONTENT_ENCODING; import static io.netty.handler.codec.http.HttpHeaderNames.CONTENT_LENGTH; -import static io.netty.handler.codec.http.HttpHeaderValues.BR; import static io.netty.handler.codec.http.HttpHeaderValues.DEFLATE; import static io.netty.handler.codec.http.HttpHeaderValues.GZIP; import static io.netty.handler.codec.http.HttpHeaderValues.IDENTITY; import static io.netty.handler.codec.http.HttpHeaderValues.X_DEFLATE; import static io.netty.handler.codec.http.HttpHeaderValues.X_GZIP; -import static io.netty.handler.codec.http.HttpHeaderValues.ZSTD; -import static io.netty.handler.codec.http.HttpHeaderValues.SNAPPY; /** * A decorating HTTP2 encoder that will compress data frames according to the {@code content-encoding} header for each @@ -67,11 +57,8 @@ public class CompressorHttp2ConnectionEncoder extends DecoratingHttp2ConnectionE private final boolean supportsCompressionOptions; - private BrotliOptions brotliOptions; private GzipOptions gzipCompressionOptions; private DeflateOptions deflateOptions; - private ZstdOptions zstdOptions; - private SnappyOptions snappyOptions; /** * Create a new {@link CompressorHttp2ConnectionEncoder} instance @@ -82,15 +69,7 @@ public class CompressorHttp2ConnectionEncoder extends DecoratingHttp2ConnectionE } private static CompressionOptions[] defaultCompressionOptions() { - if (Brotli.isAvailable()) { - return new CompressionOptions[] { - StandardCompressionOptions.brotli(), - StandardCompressionOptions.snappy(), - StandardCompressionOptions.gzip(), - StandardCompressionOptions.deflate() }; - } - return new CompressionOptions[] { StandardCompressionOptions.snappy(), - StandardCompressionOptions.gzip(), StandardCompressionOptions.deflate() }; + return new CompressionOptions[] { StandardCompressionOptions.gzip(), StandardCompressionOptions.deflate() }; } /** @@ -135,16 +114,10 @@ public class CompressorHttp2ConnectionEncoder extends DecoratingHttp2ConnectionE // This results in the static analysis of native-image identifying the instanceof BrotliOptions check // and thus BrotliOptions itself as unreachable, enabling native-image to link all classes at build time // and not complain about the missing Brotli classes. - if (Brotli.isAvailable() && compressionOptions instanceof BrotliOptions) { - brotliOptions = (BrotliOptions) compressionOptions; - } else if (compressionOptions instanceof GzipOptions) { + if (compressionOptions instanceof GzipOptions) { gzipCompressionOptions = (GzipOptions) compressionOptions; } else if (compressionOptions instanceof DeflateOptions) { deflateOptions = (DeflateOptions) compressionOptions; - } else if (compressionOptions instanceof ZstdOptions) { - zstdOptions = (ZstdOptions) compressionOptions; - } else if (compressionOptions instanceof SnappyOptions) { - snappyOptions = (SnappyOptions) compressionOptions; } else { throw new IllegalArgumentException("Unsupported " + CompressionOptions.class.getSimpleName() + ": " + compressionOptions); @@ -282,19 +255,6 @@ public class CompressorHttp2ConnectionEncoder extends DecoratingHttp2ConnectionE if (DEFLATE.contentEqualsIgnoreCase(contentEncoding) || X_DEFLATE.contentEqualsIgnoreCase(contentEncoding)) { return newCompressionChannel(ctx, ZlibWrapper.ZLIB); } - if (Brotli.isAvailable() && brotliOptions != null && BR.contentEqualsIgnoreCase(contentEncoding)) { - return new EmbeddedChannel(ctx.channel().id(), ctx.channel().metadata().hasDisconnect(), - ctx.channel().config(), new BrotliEncoder(brotliOptions.parameters())); - } - if (zstdOptions != null && ZSTD.contentEqualsIgnoreCase(contentEncoding)) { - return new EmbeddedChannel(ctx.channel().id(), ctx.channel().metadata().hasDisconnect(), - ctx.channel().config(), new ZstdEncoder(zstdOptions.compressionLevel(), - zstdOptions.blockSize(), zstdOptions.maxEncodeSize())); - } - if (snappyOptions != null && SNAPPY.contentEqualsIgnoreCase(contentEncoding)) { - return new EmbeddedChannel(ctx.channel().id(), ctx.channel().metadata().hasDisconnect(), - ctx.channel().config(), new SnappyFrameEncoder()); - } // 'identity' or unsupported return null; } diff --git a/codec-http2/src/main/java/io/netty/handler/codec/http2/DelegatingDecompressorFrameListener.java b/codec-http2/src/main/java/io/netty/handler/codec/http2/DelegatingDecompressorFrameListener.java index 6c59189be6..bbd89747ab 100644 --- a/codec-http2/src/main/java/io/netty/handler/codec/http2/DelegatingDecompressorFrameListener.java +++ b/codec-http2/src/main/java/io/netty/handler/codec/http2/DelegatingDecompressorFrameListener.java @@ -19,22 +19,17 @@ import io.netty.buffer.Unpooled; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.embedded.EmbeddedChannel; import io.netty.handler.codec.ByteToMessageDecoder; -import io.netty.handler.codec.compression.Brotli; -import io.netty.handler.codec.compression.BrotliDecoder; import io.netty.handler.codec.compression.ZlibCodecFactory; import io.netty.handler.codec.compression.ZlibWrapper; -import io.netty.handler.codec.compression.SnappyFrameDecoder; import io.netty.util.internal.UnstableApi; import static io.netty.handler.codec.http.HttpHeaderNames.CONTENT_ENCODING; import static io.netty.handler.codec.http.HttpHeaderNames.CONTENT_LENGTH; -import static io.netty.handler.codec.http.HttpHeaderValues.BR; import static io.netty.handler.codec.http.HttpHeaderValues.DEFLATE; import static io.netty.handler.codec.http.HttpHeaderValues.GZIP; import static io.netty.handler.codec.http.HttpHeaderValues.IDENTITY; import static io.netty.handler.codec.http.HttpHeaderValues.X_DEFLATE; import static io.netty.handler.codec.http.HttpHeaderValues.X_GZIP; -import static io.netty.handler.codec.http.HttpHeaderValues.SNAPPY; import static io.netty.handler.codec.http2.Http2Error.INTERNAL_ERROR; import static io.netty.handler.codec.http2.Http2Exception.streamError; import static io.netty.util.internal.ObjectUtil.checkNotNull; @@ -180,14 +175,6 @@ public class DelegatingDecompressorFrameListener extends Http2FrameListenerDecor return new EmbeddedChannel(ctx.channel().id(), ctx.channel().metadata().hasDisconnect(), ctx.channel().config(), ZlibCodecFactory.newZlibDecoder(wrapper)); } - if (Brotli.isAvailable() && BR.contentEqualsIgnoreCase(contentEncoding)) { - return new EmbeddedChannel(ctx.channel().id(), ctx.channel().metadata().hasDisconnect(), - ctx.channel().config(), new BrotliDecoder()); - } - if (SNAPPY.contentEqualsIgnoreCase(contentEncoding)) { - return new EmbeddedChannel(ctx.channel().id(), ctx.channel().metadata().hasDisconnect(), - ctx.channel().config(), new SnappyFrameDecoder()); - } // 'identity' or unsupported return null; } diff --git a/codec/src/main/java/io/netty/handler/codec/compression/StandardCompressionOptions.java b/codec/src/main/java/io/netty/handler/codec/compression/StandardCompressionOptions.java index ac2582418c..698c4b510a 100644 --- a/codec/src/main/java/io/netty/handler/codec/compression/StandardCompressionOptions.java +++ b/codec/src/main/java/io/netty/handler/codec/compression/StandardCompressionOptions.java @@ -15,10 +15,8 @@ */ package io.netty.handler.codec.compression; -import com.aayushatharva.brotli4j.encoder.Encoder; - /** - * Standard Compression Options for {@link BrotliOptions}, + * Standard Compression Options for * {@link GzipOptions} and {@link DeflateOptions} */ public final class StandardCompressionOptions { @@ -28,55 +26,6 @@ public final class StandardCompressionOptions { } /** - * Default implementation of {@link BrotliOptions} with {@link Encoder.Parameters#setQuality(int)} set to 4 - * and {@link Encoder.Parameters#setMode(Encoder.Mode)} set to {@link Encoder.Mode#TEXT} - */ - public static BrotliOptions brotli() { - return BrotliOptions.DEFAULT; - } - - /** - * Create a new {@link BrotliOptions} - * - * @param parameters {@link Encoder.Parameters} Instance - * @throws NullPointerException If {@link Encoder.Parameters} is {@code null} - */ - public static BrotliOptions brotli(Encoder.Parameters parameters) { - return new BrotliOptions(parameters); - } - - /** - * Default implementation of {@link ZstdOptions} with{compressionLevel(int)} set to - * {@link ZstdConstants#DEFAULT_COMPRESSION_LEVEL},{@link ZstdConstants#DEFAULT_BLOCK_SIZE}, - * {@link ZstdConstants#MAX_BLOCK_SIZE} - */ - public static ZstdOptions zstd() { - return ZstdOptions.DEFAULT; - } - - /** - * Create a new {@link ZstdOptions} - * - * @param blockSize - * is used to calculate the compressionLevel - * @param maxEncodeSize - * specifies the size of the largest compressed object - * @param compressionLevel - * specifies the level of the compression - */ - public static ZstdOptions zstd(int compressionLevel, int blockSize, int maxEncodeSize) { - return new ZstdOptions(compressionLevel, blockSize, maxEncodeSize); - } - - /** - * Create a new {@link SnappyOptions} - * - */ - public static SnappyOptions snappy() { - return new SnappyOptions(); - } - - /** * Default implementation of {@link GzipOptions} with * {@code compressionLevel()} set to 6, {@code windowBits()} set to 15 and {@code memLevel()} set to 8. */ -- 2.44.0
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor