Skip to content

Commit

Permalink
Set compressionOptions to null as the default state when compression …
Browse files Browse the repository at this point in the history
…is disabled

- Updated compressionOptions to default to null when compression is not explicitly configured.
- Ensures a clean default state, reflecting that no compression settings are applied unless enabled.
  • Loading branch information
raccoonback committed Jan 9, 2025
1 parent 100d2da commit 3de0d82
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ final class Http2StreamBridgeServerHandler extends ChannelDuplexHandler {

Http2StreamBridgeServerHandler(
@Nullable BiPredicate<HttpServerRequest, HttpServerResponse> compress,
HttpCompressionOptionsSpec compressionOptions,
@Nullable HttpCompressionOptionsSpec compressionOptions,
ServerCookieDecoder decoder,
ServerCookieEncoder encoder,
HttpServerFormDecoderProvider formDecoderProvider,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ final class Http3Codec extends ChannelInitializer<QuicStreamChannel> {
@Nullable Function<String, String> methodTagValue,
@Nullable ChannelMetricsRecorder metricsRecorder,
int minCompressionSize,
HttpCompressionOptionsSpec compressionOptions,
@Nullable HttpCompressionOptionsSpec compressionOptions,
ChannelOperations.OnSetup opsFactory,
@Nullable Duration readTimeout,
@Nullable Duration requestTimeout,
Expand Down Expand Up @@ -170,7 +170,7 @@ static ChannelHandler newHttp3ServerConnectionHandler(
@Nullable Function<String, String> methodTagValue,
@Nullable ChannelMetricsRecorder metricsRecorder,
int minCompressionSize,
HttpCompressionOptionsSpec compressionOptions,
@Nullable HttpCompressionOptionsSpec compressionOptions,
ChannelOperations.OnSetup opsFactory,
@Nullable Duration readTimeout,
@Nullable Duration requestTimeout,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ final class Http3ServerOperations extends HttpServerOperations {
ConnectionObserver listener,
HttpRequest nettyRequest,
@Nullable BiPredicate<HttpServerRequest, HttpServerResponse> compressionPredicate,
HttpCompressionOptionsSpec compressionOptions,
@Nullable HttpCompressionOptionsSpec compressionOptions,
ConnectionInfo connectionInfo,
ServerCookieDecoder decoder,
ServerCookieEncoder encoder,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ final class Http3StreamBridgeServerHandler extends ChannelDuplexHandler {

Http3StreamBridgeServerHandler(
@Nullable BiPredicate<HttpServerRequest, HttpServerResponse> compress,
HttpCompressionOptionsSpec compressionOptions,
@Nullable HttpCompressionOptionsSpec compressionOptions,
ServerCookieDecoder decoder,
ServerCookieEncoder encoder,
HttpServerFormDecoderProvider formDecoderProvider,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ public Function<String, String> uriTagValue() {
this.httpMessageLogFactory = ReactorNettyHttpMessageLogFactory.INSTANCE;
this.maxKeepAliveRequests = -1;
this.minCompressionSize = -1;
this.compressionOptions = HttpCompressionOptionsSpec.provideDefault();
this.compressionOptions = null;
this.protocols = new HttpProtocol[]{HttpProtocol.HTTP11};
this._protocols = h11;
this.proxyProtocolSupportType = ProxyProtocolSupportType.OFF;
Expand Down Expand Up @@ -496,7 +496,7 @@ static void addStreamHandlers(Channel ch,
@Nullable Function<String, String> methodTagValue,
@Nullable ChannelMetricsRecorder metricsRecorder,
int minCompressionSize,
HttpCompressionOptionsSpec compressionOptions,
@Nullable HttpCompressionOptionsSpec compressionOptions,
ChannelOperations.OnSetup opsFactory,
@Nullable Duration readTimeout,
@Nullable Duration requestTimeout,
Expand Down Expand Up @@ -610,7 +610,7 @@ static void configureHttp3Pipeline(
@Nullable Function<String, String> methodTagValue,
@Nullable ChannelMetricsRecorder metricsRecorder,
int minCompressionSize,
HttpCompressionOptionsSpec compressionOptions,
@Nullable HttpCompressionOptionsSpec compressionOptions,
ChannelOperations.OnSetup opsFactory,
@Nullable Duration readTimeout,
@Nullable Duration requestTimeout,
Expand Down Expand Up @@ -646,7 +646,7 @@ static void configureH2Pipeline(ChannelPipeline p,
@Nullable Function<String, String> methodTagValue,
@Nullable ChannelMetricsRecorder metricsRecorder,
int minCompressionSize,
HttpCompressionOptionsSpec compressionOptions,
@Nullable HttpCompressionOptionsSpec compressionOptions,
ChannelOperations.OnSetup opsFactory,
@Nullable Duration readTimeout,
@Nullable Duration requestTimeout,
Expand Down Expand Up @@ -717,7 +717,7 @@ static void configureHttp11OrH2CleartextPipeline(ChannelPipeline p,
@Nullable Function<String, String> methodTagValue,
@Nullable ChannelMetricsRecorder metricsRecorder,
int minCompressionSize,
HttpCompressionOptionsSpec compressionOptions,
@Nullable HttpCompressionOptionsSpec compressionOptions,
ChannelOperations.OnSetup opsFactory,
@Nullable Duration readTimeout,
@Nullable Duration requestTimeout,
Expand Down Expand Up @@ -806,7 +806,7 @@ static void configureHttp11Pipeline(ChannelPipeline p,
@Nullable Function<String, String> methodTagValue,
@Nullable ChannelMetricsRecorder metricsRecorder,
int minCompressionSize,
HttpCompressionOptionsSpec compressionOptions,
@Nullable HttpCompressionOptionsSpec compressionOptions,
@Nullable Duration readTimeout,
@Nullable Duration requestTimeout,
@Nullable Function<String, String> uriTagValue) {
Expand Down Expand Up @@ -1037,7 +1037,7 @@ static final class H2Codec extends ChannelInitializer<Channel> {
@Nullable Function<String, String> methodTagValue,
@Nullable ChannelMetricsRecorder metricsRecorder,
int minCompressionSize,
HttpCompressionOptionsSpec compressionOptions,
@Nullable HttpCompressionOptionsSpec compressionOptions,
ChannelOperations.OnSetup opsFactory,
@Nullable Duration readTimeout,
@Nullable Duration requestTimeout,
Expand Down Expand Up @@ -1113,7 +1113,7 @@ static final class Http11OrH2CleartextCodec extends ChannelInitializer<Channel>
@Nullable Function<String, String> methodTagValue,
@Nullable ChannelMetricsRecorder metricsRecorder,
int minCompressionSize,
HttpCompressionOptionsSpec compressionOptions,
@Nullable HttpCompressionOptionsSpec compressionOptions,
ChannelOperations.OnSetup opsFactory,
@Nullable Duration readTimeout,
@Nullable Duration requestTimeout,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ class HttpServerOperations extends HttpOperations<HttpServerRequest, HttpServerR

HttpServerOperations(Connection c, ConnectionObserver listener, HttpRequest nettyRequest,
@Nullable BiPredicate<HttpServerRequest, HttpServerResponse> compressionPredicate,
HttpCompressionOptionsSpec compressionOptions,
@Nullable HttpCompressionOptionsSpec compressionOptions,
ConnectionInfo connectionInfo,
ServerCookieDecoder decoder,
ServerCookieEncoder encoder,
Expand Down Expand Up @@ -1325,7 +1325,7 @@ static final class FailedHttpServerRequest extends HttpServerOperations {
ZonedDateTime timestamp,
ConnectionInfo connectionInfo,
boolean validateHeaders) {
super(c, listener, nettyRequest, null, HttpCompressionOptionsSpec.provideDefault(), connectionInfo,
super(c, listener, nettyRequest, null, null, connectionInfo,
ServerCookieDecoder.STRICT, ServerCookieEncoder.STRICT, DEFAULT_FORM_DECODER_SPEC, httpMessageLogFactory, isHttp2,
null, null, null, secure, timestamp, validateHeaders);
this.customResponse = nettyResponse;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ final class HttpTrafficHandler extends ChannelDuplexHandler implements Runnable

HttpTrafficHandler(
@Nullable BiPredicate<HttpServerRequest, HttpServerResponse> compress,
HttpCompressionOptionsSpec compressionOptions,
@Nullable HttpCompressionOptionsSpec compressionOptions,
ServerCookieDecoder decoder,
ServerCookieEncoder encoder,
HttpServerFormDecoderProvider formDecoderProvider,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
*/
package reactor.netty.http.server;

import java.util.ArrayList;
import java.util.List;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPromise;
Expand All @@ -32,6 +29,10 @@
import io.netty.handler.codec.http.LastHttpContent;
import io.netty.util.ReferenceCountUtil;
import reactor.netty.http.server.compression.HttpCompressionOptionsSpec;
import reactor.util.annotation.Nullable;

import java.util.ArrayList;
import java.util.List;

/**
* {@link HttpContentCompressor} to enable on-demand compression.
Expand All @@ -47,7 +48,11 @@ private SimpleCompressionHandler(CompressionOptions... options) {
super(options);
}

static SimpleCompressionHandler create(HttpCompressionOptionsSpec compressionOptions) {
static SimpleCompressionHandler create(@Nullable HttpCompressionOptionsSpec compressionOptions) {
if (compressionOptions == null) {
return new SimpleCompressionHandler();
}

return new SimpleCompressionHandler(
compressionOptions.adapt()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,6 @@ else if (Zstd.isAvailable() && option instanceof ZstdOption) {
}
}

public static HttpCompressionOptionsSpec provideDefault() {
return new HttpCompressionOptionsSpec();
}

public CompressionOptions[] adapt() {
List<CompressionOptions> options = new ArrayList<>(
Arrays.asList(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@
import reactor.netty.http.client.HttpClientRequest;
import reactor.netty.http.client.PrematureCloseException;
import reactor.netty.http.logging.ReactorNettyHttpMessageLogFactory;
import reactor.netty.http.server.compression.HttpCompressionOptionsSpec;
import reactor.netty.resources.ConnectionProvider;
import reactor.netty.resources.LoopResources;
import reactor.netty.tcp.SslProvider;
Expand Down Expand Up @@ -2215,7 +2214,7 @@ private void doTestStatus(HttpResponseStatus status) {
ConnectionObserver.emptyListener(),
new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/"),
null,
HttpCompressionOptionsSpec.provideDefault(),
null,
new ConnectionInfo(localSocketAddress, DEFAULT_HOST_NAME, DEFAULT_HTTP_PORT, remoteSocketAddress, "http", true),
ServerCookieDecoder.STRICT,
ServerCookieEncoder.STRICT,
Expand Down Expand Up @@ -3274,7 +3273,7 @@ private void doTestIsFormUrlencoded(String headerValue, boolean expectation) {
ConnectionObserver.emptyListener(),
request,
null,
HttpCompressionOptionsSpec.provideDefault(),
null,
new ConnectionInfo(localSocketAddress, DEFAULT_HOST_NAME, DEFAULT_HTTP_PORT, remoteSocketAddress, "http", true),
ServerCookieDecoder.STRICT,
ServerCookieEncoder.STRICT,
Expand Down

0 comments on commit 3de0d82

Please sign in to comment.