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
brotli support in HttpClient #2848
base: main
Are you sure you want to change the base?
Conversation
@violetagg Please take a look :) |
@sullis I can take a look at the end of the week. Can you verify that when we do not have Brotli in the class path the native-image functionality is still working OK? When we have native-image we need to be careful with reflection and Brotli.isAvailable does reflection. |
I tested this one When there is no One can see
I'm using When I have When I have
|
I'm seeing that
While for example in
|
Interesting. I'll take a closer look this weekend. |
@sullis it will be great if you can rebase so that you can pick up the GraalVM smoke tests change. |
3717140
to
532fd53
Compare
Rebase done. |
@sullis If you want we can proceed with this. We will state that Brotli supports native image only for
|
Sounds good to me! |
@@ -598,7 +612,7 @@ else if (metricsRecorder instanceof ContextAwareHttpClientMetricsRecorder) { | |||
} | |||
} | |||
|
|||
static void configureHttp2Pipeline(ChannelPipeline p, boolean acceptGzip, HttpResponseDecoderSpec decoder, | |||
static void configureHttp2Pipeline(ChannelPipeline p, boolean acceptGzip, boolean acceptBrotli, HttpResponseDecoderSpec decoder, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is not needed:
static void configureHttp2Pipeline(ChannelPipeline p, boolean acceptGzip, boolean acceptBrotli, HttpResponseDecoderSpec decoder, | |
static void configureHttp2Pipeline(ChannelPipeline p, boolean acceptGzip, HttpResponseDecoderSpec decoder, |
@@ -905,10 +930,10 @@ public void channelActive(ChannelHandlerContext ctx) { | |||
log.debug(format(ctx.channel(), "Negotiated application-level protocol [" + protocol + "]")); | |||
} | |||
if (ApplicationProtocolNames.HTTP_2.equals(protocol)) { | |||
configureHttp2Pipeline(ctx.channel().pipeline(), acceptGzip, decoder, http2Settings, observer); | |||
configureHttp2Pipeline(ctx.channel().pipeline(), acceptGzip, acceptBrotli, decoder, http2Settings, observer); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is not needed:
configureHttp2Pipeline(ctx.channel().pipeline(), acceptGzip, acceptBrotli, decoder, http2Settings, observer); | |
configureHttp2Pipeline(ctx.channel().pipeline(), acceptGzip, decoder, http2Settings, observer); |
} | ||
else if ((protocols & h2) == h2) { | ||
configureHttp2Pipeline(channel.pipeline(), acceptGzip, decoder, http2Settings, observer); | ||
configureHttp2Pipeline(channel.pipeline(), acceptGzip, acceptBrotli, decoder, http2Settings, observer); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is not needed:
configureHttp2Pipeline(channel.pipeline(), acceptGzip, acceptBrotli, decoder, http2Settings, observer); | |
configureHttp2Pipeline(channel.pipeline(), acceptGzip, decoder, http2Settings, observer); |
} | ||
else if ((protocols & h2c) == h2c) { | ||
configureHttp2Pipeline(channel.pipeline(), acceptGzip, decoder, http2Settings, observer); | ||
configureHttp2Pipeline(channel.pipeline(), acceptGzip, acceptBrotli, decoder, http2Settings, observer); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is not needed:
configureHttp2Pipeline(channel.pipeline(), acceptGzip, acceptBrotli, decoder, http2Settings, observer); | |
configureHttp2Pipeline(channel.pipeline(), acceptGzip, decoder, http2Settings, observer); |
@@ -515,7 +516,13 @@ public final HttpClient baseUrl(String baseUrl) { | |||
* @return a new {@link HttpClient} | |||
*/ | |||
public final HttpClient compress(boolean compressionEnabled) { | |||
configuration().headers.remove(HttpHeaderNames.ACCEPT_ENCODING); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will remove any custom Accept-Encoding
header that was set prior this invocation.
Why do we need to do this? It will be better to preserve the custom headers.
if (brotliEnabled) { | ||
assertThat(Brotli.isAvailable()).isTrue(); | ||
client = client.compress(true); | ||
client.configuration().headers = client.configuration().headers() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you need this? The compress
method should add the header.
.response((r, buf) -> buf.asString() | ||
.elementAt(0) | ||
.zipWith(Mono.just(r)))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.response((r, buf) -> buf.asString() | |
.elementAt(0) | |
.zipWith(Mono.just(r)))) | |
.responseSingle((r, buf) -> buf.asString().zipWith(Mono.just(r)))) |
532fd53
to
b78270a
Compare
56434f8
to
b0b2878
Compare
b0b2878
to
794e69c
Compare
rebased |
794e69c
to
0b893c4
Compare
enable Brotli compression support in the Reactor http client.