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 f92b467e65..9fb30f768c 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
@@ -186,8 +186,7 @@ public class HttpContentCompressor extends HttpContentEncoder {
} else if (compressionOption instanceof DeflateOptions) {
deflateOptions = (DeflateOptions) compressionOption;
} else if (compressionOption instanceof ZstdOptions) {
- // zstd might not be available
- zstdOptions = Zstd.isAvailable() ? (ZstdOptions) compressionOption : null;
+ zstdOptions = (ZstdOptions) compressionOption;
} else {
throw new IllegalArgumentException("Unsupported " + CompressionOptions.class.getSimpleName() +
": " + compressionOption);
diff --git a/codec-http2/pom.xml b/codec-http2/pom.xml
index e9d74896ef..fd47bcb870 100644
--- a/codec-http2/pom.xml
+++ b/codec-http2/pom.xml
@@ -95,6 +95,11 @@
brotli4j
true
+
+ com.github.luben
+ zstd-jni
+ true
+
diff --git a/codec/src/main/java/io/netty/handler/codec/compression/BrotliOptions.java b/codec/src/main/java/io/netty/handler/codec/compression/BrotliOptions.java
index b2a6934aa5..737f5d149c 100644
--- a/codec/src/main/java/io/netty/handler/codec/compression/BrotliOptions.java
+++ b/codec/src/main/java/io/netty/handler/codec/compression/BrotliOptions.java
@@ -34,11 +34,11 @@ public final class BrotliOptions implements CompressionOptions {
);
BrotliOptions(Encoder.Parameters parameters) {
- this.parameters = ObjectUtil.checkNotNull(parameters, "Parameters");
-
if (!Brotli.isAvailable()) {
throw new IllegalStateException("Brotli is not available", Brotli.cause());
}
+
+ this.parameters = ObjectUtil.checkNotNull(parameters, "Parameters");
}
public Encoder.Parameters parameters() {
diff --git a/codec/src/main/java/io/netty/handler/codec/compression/ZstdOptions.java b/codec/src/main/java/io/netty/handler/codec/compression/ZstdOptions.java
index 3c8c243a55..110a90fb39 100644
--- a/codec/src/main/java/io/netty/handler/codec/compression/ZstdOptions.java
+++ b/codec/src/main/java/io/netty/handler/codec/compression/ZstdOptions.java
@@ -50,6 +50,10 @@ public class ZstdOptions implements CompressionOptions {
* specifies the level of the compression
*/
ZstdOptions(int compressionLevel, int blockSize, int maxEncodeSize) {
+ if (!Zstd.isAvailable()) {
+ throw new IllegalStateException("zstd-jni is not available", Zstd.cause());
+ }
+
this.compressionLevel = ObjectUtil.checkInRange(compressionLevel, 0, MAX_COMPRESSION_LEVEL, "compressionLevel");
this.blockSize = ObjectUtil.checkPositive(blockSize, "blockSize");
this.maxEncodeSize = ObjectUtil.checkPositive(maxEncodeSize, "maxEncodeSize");