Skip to content

Commit ed41748

Browse files
zakkakgsmet
authored andcommitted
Enable Brotli decompression
Note: Zstd and Snappy remain unsupported. Fixes #43392 (cherry picked from commit 588d3db)
1 parent 7f81c66 commit ed41748

File tree

1 file changed

+23
-16
lines changed

1 file changed

+23
-16
lines changed

extensions/netty/runtime/src/main/java/io/quarkus/netty/runtime/graal/NettySubstitutions.java

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.quarkus.netty.runtime.graal;
22

3+
import static io.netty.handler.codec.http.HttpHeaderValues.BR;
34
import static io.netty.handler.codec.http.HttpHeaderValues.DEFLATE;
45
import static io.netty.handler.codec.http.HttpHeaderValues.GZIP;
56
import static io.netty.handler.codec.http.HttpHeaderValues.X_DEFLATE;
@@ -43,13 +44,13 @@
4344
import io.netty.buffer.ByteBufAllocator;
4445
import io.netty.channel.Channel;
4546
import io.netty.channel.ChannelFuture;
46-
import io.netty.channel.ChannelHandler;
4747
import io.netty.channel.ChannelHandlerContext;
4848
import io.netty.channel.DefaultChannelPromise;
4949
import io.netty.channel.embedded.EmbeddedChannel;
50+
import io.netty.handler.codec.compression.Brotli;
51+
import io.netty.handler.codec.compression.BrotliDecoder;
5052
import io.netty.handler.codec.compression.ZlibCodecFactory;
5153
import io.netty.handler.codec.compression.ZlibWrapper;
52-
import io.netty.handler.codec.http.HttpHeaderValues;
5354
import io.netty.handler.codec.http2.Http2Exception;
5455
import io.netty.handler.ssl.ApplicationProtocolConfig;
5556
import io.netty.handler.ssl.ApplicationProtocolConfig.SelectorFailureBehavior;
@@ -518,6 +519,10 @@ protected EmbeddedChannel newContentDecoder(String contentEncoding) throws Excep
518519
return new EmbeddedChannel(ctx.channel().id(), ctx.channel().metadata().hasDisconnect(),
519520
ctx.channel().config(), ZlibCodecFactory.newZlibDecoder(wrapper));
520521
}
522+
if (Brotli.isAvailable() && BR.contentEqualsIgnoreCase(contentEncoding)) {
523+
return new EmbeddedChannel(ctx.channel().id(), ctx.channel().metadata().hasDisconnect(),
524+
ctx.channel().config(), new BrotliDecoder());
525+
}
521526

522527
// 'identity' or unsupported
523528
return null;
@@ -533,21 +538,23 @@ final class Target_io_netty_handler_codec_http2_DelegatingDecompressorFrameListe
533538
@Substitute
534539
protected EmbeddedChannel newContentDecompressor(ChannelHandlerContext ctx, CharSequence contentEncoding)
535540
throws Http2Exception {
536-
if (!HttpHeaderValues.GZIP.contentEqualsIgnoreCase(contentEncoding)
537-
&& !HttpHeaderValues.X_GZIP.contentEqualsIgnoreCase(contentEncoding)) {
538-
if (!HttpHeaderValues.DEFLATE.contentEqualsIgnoreCase(contentEncoding)
539-
&& !HttpHeaderValues.X_DEFLATE.contentEqualsIgnoreCase(contentEncoding)) {
540-
return null;
541-
} else {
542-
ZlibWrapper wrapper = this.strict ? ZlibWrapper.ZLIB : ZlibWrapper.ZLIB_OR_NONE;
543-
return new EmbeddedChannel(ctx.channel().id(), ctx.channel().metadata().hasDisconnect(),
544-
ctx.channel().config(),
545-
new ChannelHandler[] { ZlibCodecFactory.newZlibDecoder(wrapper) });
546-
}
547-
} else {
548-
return new EmbeddedChannel(ctx.channel().id(), ctx.channel().metadata().hasDisconnect(), ctx.channel().config(),
549-
new ChannelHandler[] { ZlibCodecFactory.newZlibDecoder(ZlibWrapper.GZIP) });
541+
if (GZIP.contentEqualsIgnoreCase(contentEncoding) || X_GZIP.contentEqualsIgnoreCase(contentEncoding)) {
542+
return new EmbeddedChannel(ctx.channel().id(), ctx.channel().metadata().hasDisconnect(),
543+
ctx.channel().config(), ZlibCodecFactory.newZlibDecoder(ZlibWrapper.GZIP));
550544
}
545+
if (DEFLATE.contentEqualsIgnoreCase(contentEncoding) || X_DEFLATE.contentEqualsIgnoreCase(contentEncoding)) {
546+
final ZlibWrapper wrapper = strict ? ZlibWrapper.ZLIB : ZlibWrapper.ZLIB_OR_NONE;
547+
// To be strict, 'deflate' means ZLIB, but some servers were not implemented correctly.
548+
return new EmbeddedChannel(ctx.channel().id(), ctx.channel().metadata().hasDisconnect(),
549+
ctx.channel().config(), ZlibCodecFactory.newZlibDecoder(wrapper));
550+
}
551+
if (Brotli.isAvailable() && BR.contentEqualsIgnoreCase(contentEncoding)) {
552+
return new EmbeddedChannel(ctx.channel().id(), ctx.channel().metadata().hasDisconnect(),
553+
ctx.channel().config(), new BrotliDecoder());
554+
}
555+
556+
// 'identity' or unsupported
557+
return null;
551558
}
552559
}
553560

0 commit comments

Comments
 (0)