Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support brotli #1938

Merged
merged 4 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,42 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.aayushatharva.brotli4j</groupId>
<artifactId>brotli4j</artifactId>
<scope>test</scope>
sullis marked this conversation as resolved.
Show resolved Hide resolved
</dependency>
<dependency>
<groupId>com.aayushatharva.brotli4j</groupId>
<artifactId>native-linux-x86_64</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.aayushatharva.brotli4j</groupId>
<artifactId>native-linux-aarch64</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.aayushatharva.brotli4j</groupId>
<artifactId>native-linux-riscv64</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.aayushatharva.brotli4j</groupId>
<artifactId>native-osx-x86_64</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.aayushatharva.brotli4j</groupId>
<artifactId>native-osx-aarch64</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.aayushatharva.brotli4j</groupId>
<artifactId>native-windows-x86_64</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
}

Expand Down
13 changes: 13 additions & 0 deletions client/src/test/java/org/asynchttpclient/netty/NettyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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());
}
}
36 changes: 36 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@

<netty.version>4.1.107.Final</netty.version>
<netty.iouring>0.0.25.Final</netty.iouring>
<brotli4j.version>1.16.0</brotli4j.version>
<slf4j.version>2.0.12</slf4j.version>
<activation.version>2.0.1</activation.version>
<logback.version>1.4.11</logback.version>
Expand Down Expand Up @@ -117,6 +118,41 @@
<artifactId>netty-leak-detector-junit-extension</artifactId>
<version>0.0.2</version>
</dependency>
<dependency>
<groupId>com.aayushatharva.brotli4j</groupId>
<artifactId>brotli4j</artifactId>
<version>${brotli4j.version}</version>
</dependency>
<dependency>
<groupId>com.aayushatharva.brotli4j</groupId>
<artifactId>native-linux-x86_64</artifactId>
<version>${brotli4j.version}</version>
</dependency>
<dependency>
<groupId>com.aayushatharva.brotli4j</groupId>
<artifactId>native-linux-aarch64</artifactId>
<version>${brotli4j.version}</version>
</dependency>
<dependency>
<groupId>com.aayushatharva.brotli4j</groupId>
<artifactId>native-linux-riscv64</artifactId>
<version>${brotli4j.version}</version>
</dependency>
<dependency>
<groupId>com.aayushatharva.brotli4j</groupId>
<artifactId>native-osx-x86_64</artifactId>
<version>${brotli4j.version}</version>
</dependency>
<dependency>
<groupId>com.aayushatharva.brotli4j</groupId>
<artifactId>native-osx-aarch64</artifactId>
<version>${brotli4j.version}</version>
</dependency>
<dependency>
<groupId>com.aayushatharva.brotli4j</groupId>
<artifactId>native-windows-x86_64</artifactId>
<version>${brotli4j.version}</version>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down