From b1b9b775854380ecbe90a82a38715cdcfa7d5eb5 Mon Sep 17 00:00:00 2001 From: sullis Date: Wed, 28 Feb 2024 10:21:34 -0800 Subject: [PATCH 1/4] support brotli --- client/pom.xml | 36 +++++++++++++++++++ .../netty/request/NettyRequestFactory.java | 12 +++++-- .../org/asynchttpclient/netty/NettyTest.java | 13 +++++++ pom.xml | 36 +++++++++++++++++++ 4 files changed, 94 insertions(+), 3 deletions(-) diff --git a/client/pom.xml b/client/pom.xml index 7a28070c4..bd5b88f90 100644 --- a/client/pom.xml +++ b/client/pom.xml @@ -102,6 +102,42 @@ test + + com.aayushatharva.brotli4j + brotli4j + test + + + com.aayushatharva.brotli4j + native-linux-x86_64 + test + + + com.aayushatharva.brotli4j + native-linux-aarch64 + test + + + com.aayushatharva.brotli4j + native-linux-riscv64 + test + + + com.aayushatharva.brotli4j + native-osx-x86_64 + test + + + com.aayushatharva.brotli4j + native-osx-aarch64 + test + + + com.aayushatharva.brotli4j + native-windows-x86_64 + test + + org.eclipse.jetty jetty-servlet diff --git a/client/src/main/java/org/asynchttpclient/netty/request/NettyRequestFactory.java b/client/src/main/java/org/asynchttpclient/netty/request/NettyRequestFactory.java index 317c4522f..07d1f76a2 100755 --- a/client/src/main/java/org/asynchttpclient/netty/request/NettyRequestFactory.java +++ b/client/src/main/java/org/asynchttpclient/netty/request/NettyRequestFactory.java @@ -17,6 +17,7 @@ import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; +import io.netty.handler.codec.compression.Brotli; import io.netty.handler.codec.http.DefaultFullHttpRequest; import io.netty.handler.codec.http.DefaultHttpRequest; import io.netty.handler.codec.http.HttpHeaderValues; @@ -173,13 +174,18 @@ public NettyRequest newNettyRequest(Request request, boolean performConnectReque String userDefinedAcceptEncoding = headers.get(ACCEPT_ENCODING); if (userDefinedAcceptEncoding != null) { if (config.isEnableAutomaticDecompression()) { - // we don't support Brotli ATM, for automatic decompression. - // For manual decompression by user, any encoding may suite, so leave untouched - headers.set(ACCEPT_ENCODING, filterOutBrotliFromAcceptEncoding(userDefinedAcceptEncoding)); + if (!Brotli.isAvailable()) { + // Brotli is not available. + // For manual decompression by user, any encoding may suite, so leave untouched + headers.set(ACCEPT_ENCODING, filterOutBrotliFromAcceptEncoding(userDefinedAcceptEncoding)); + } } } else if (config.isCompressionEnforced()) { // Add Accept Encoding header if compression is enforced headers.set(ACCEPT_ENCODING, GZIP_DEFLATE); + if (Brotli.isAvailable()) { + headers.add(ACCEPT_ENCODING, HttpHeaderValues.BR); + } } } diff --git a/client/src/test/java/org/asynchttpclient/netty/NettyTest.java b/client/src/test/java/org/asynchttpclient/netty/NettyTest.java index 6f7e034b9..9a0293be3 100644 --- a/client/src/test/java/org/asynchttpclient/netty/NettyTest.java +++ b/client/src/test/java/org/asynchttpclient/netty/NettyTest.java @@ -2,6 +2,7 @@ import io.netty.channel.epoll.Epoll; import io.netty.channel.kqueue.KQueue; +import io.netty.handler.codec.compression.Brotli; import io.netty.incubator.channel.uring.IOUring; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.EnabledOnOs; @@ -27,4 +28,16 @@ public void ioUringIsAvailableOnLinux() { public void kqueueIsAvailableOnMac() { assertTrue(KQueue.isAvailable()); } + + @Test + @EnabledOnOs(value = OS.LINUX) + public void brotliIsAvailableOnLinux() { + assertTrue(Brotli.isAvailable()); + } + + @Test + @EnabledOnOs(value = OS.MAC) + public void brotliIsAvailableOnMac() { + assertTrue(Brotli.isAvailable()); + } } diff --git a/pom.xml b/pom.xml index 1e50f5d0c..db96729cf 100644 --- a/pom.xml +++ b/pom.xml @@ -60,6 +60,7 @@ 4.1.107.Final 0.0.25.Final + 1.16.0 2.0.12 2.0.1 1.4.11 @@ -117,6 +118,41 @@ netty-leak-detector-junit-extension 0.0.2 + + com.aayushatharva.brotli4j + brotli4j + ${brotli4j.version} + + + com.aayushatharva.brotli4j + native-linux-x86_64 + ${brotli4j.version} + + + com.aayushatharva.brotli4j + native-linux-aarch64 + ${brotli4j.version} + + + com.aayushatharva.brotli4j + native-linux-riscv64 + ${brotli4j.version} + + + com.aayushatharva.brotli4j + native-osx-x86_64 + ${brotli4j.version} + + + com.aayushatharva.brotli4j + native-osx-aarch64 + ${brotli4j.version} + + + com.aayushatharva.brotli4j + native-windows-x86_64 + ${brotli4j.version} + From 7dc2614c734da00b42932c9d58e3432cc62c35e7 Mon Sep 17 00:00:00 2001 From: sullis Date: Wed, 28 Feb 2024 10:44:20 -0800 Subject: [PATCH 2/4] brotli4j optional=true --- client/pom.xml | 35 ----------------------------------- pom.xml | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 35 deletions(-) diff --git a/client/pom.xml b/client/pom.xml index bd5b88f90..c430e489f 100644 --- a/client/pom.xml +++ b/client/pom.xml @@ -102,41 +102,6 @@ test - - com.aayushatharva.brotli4j - brotli4j - test - - - com.aayushatharva.brotli4j - native-linux-x86_64 - test - - - com.aayushatharva.brotli4j - native-linux-aarch64 - test - - - com.aayushatharva.brotli4j - native-linux-riscv64 - test - - - com.aayushatharva.brotli4j - native-osx-x86_64 - test - - - com.aayushatharva.brotli4j - native-osx-aarch64 - test - - - com.aayushatharva.brotli4j - native-windows-x86_64 - test - org.eclipse.jetty diff --git a/pom.xml b/pom.xml index db96729cf..36b59e006 100644 --- a/pom.xml +++ b/pom.xml @@ -259,6 +259,42 @@ true + + com.aayushatharva.brotli4j + brotli4j + true + + + com.aayushatharva.brotli4j + native-linux-x86_64 + true + + + com.aayushatharva.brotli4j + native-linux-aarch64 + true + + + com.aayushatharva.brotli4j + native-linux-riscv64 + true + + + com.aayushatharva.brotli4j + native-osx-x86_64 + true + + + com.aayushatharva.brotli4j + native-osx-aarch64 + true + + + com.aayushatharva.brotli4j + native-windows-x86_64 + true + + org.slf4j slf4j-api From 5b9afe4b56a5fc2dd76b429608c41ee874f150be Mon Sep 17 00:00:00 2001 From: sullis Date: Wed, 28 Feb 2024 10:44:55 -0800 Subject: [PATCH 3/4] cleanup whitespace --- client/pom.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/client/pom.xml b/client/pom.xml index c430e489f..7a28070c4 100644 --- a/client/pom.xml +++ b/client/pom.xml @@ -102,7 +102,6 @@ test - org.eclipse.jetty jetty-servlet From a7fa29dd91d5954199685a63bcb08bda7abe427e Mon Sep 17 00:00:00 2001 From: sullis Date: Fri, 1 Mar 2024 08:13:31 -0800 Subject: [PATCH 4/4] fix brotli4j dependencies --- pom.xml | 44 ++++++++------------------------------------ 1 file changed, 8 insertions(+), 36 deletions(-) diff --git a/pom.xml b/pom.xml index 36b59e006..9849139fd 100644 --- a/pom.xml +++ b/pom.xml @@ -1,6 +1,6 @@