Skip to content

Commit b466fb8

Browse files
committed
Add SETTING_H2C_MAX_CONTENT_LENGTH to configure h2cMaxContentLength for reactor-netty4 transport
Signed-off-by: Andriy Redko <andriy.redko@aiven.io>
1 parent 3de626a commit b466fb8

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

plugins/transport-reactor-netty4/src/main/java/org/opensearch/http/reactor/netty4/ReactorNetty4HttpServerTransport.java

+17
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.opensearch.common.util.concurrent.OpenSearchExecutors;
1919
import org.opensearch.common.util.io.IOUtils;
2020
import org.opensearch.common.util.net.NetUtils;
21+
import org.opensearch.core.common.unit.ByteSizeUnit;
2122
import org.opensearch.core.common.unit.ByteSizeValue;
2223
import org.opensearch.core.xcontent.NamedXContentRegistry;
2324
import org.opensearch.http.AbstractHttpServerTransport;
@@ -87,6 +88,19 @@ public class ReactorNetty4HttpServerTransport extends AbstractHttpServerTranspor
8788
private static final String SETTING_KEY_HTTP_NETTY_MAX_COMPOSITE_BUFFER_COMPONENTS = "http.netty.max_composite_buffer_components";
8889
private static final ByteSizeValue MTU = new ByteSizeValue(Long.parseLong(System.getProperty("opensearch.net.mtu", "1500")));
8990

91+
/**
92+
* Configure the maximum length of the content of the HTTP/2.0 clear-text upgrade request.
93+
* By default the server will reject an upgrade request with non-empty content,
94+
* because the upgrade request is most likely a GET request. If the client sends
95+
* a non-GET upgrade request, {@link #h2cMaxContentLength} specifies the maximum
96+
* length of the content of the upgrade request.
97+
*/
98+
public static final Setting<ByteSizeValue> SETTING_H2C_MAX_CONTENT_LENGTH = Setting.byteSizeSetting(
99+
"h2c.max_content_length",
100+
new ByteSizeValue(65536, ByteSizeUnit.KB),
101+
Property.NodeScope
102+
);
103+
90104
/**
91105
* The number of Reactor Netty HTTP workers
92106
*/
@@ -133,6 +147,7 @@ public class ReactorNetty4HttpServerTransport extends AbstractHttpServerTranspor
133147
private final ByteSizeValue maxInitialLineLength;
134148
private final ByteSizeValue maxHeaderSize;
135149
private final ByteSizeValue maxChunkSize;
150+
private final ByteSizeValue h2cMaxContentLength;
136151
private final SecureHttpTransportSettingsProvider secureHttpTransportSettingsProvider;
137152
private volatile SharedGroupFactory.SharedGroup sharedGroup;
138153
private volatile DisposableServer disposableServer;
@@ -208,6 +223,7 @@ public ReactorNetty4HttpServerTransport(
208223
this.maxCompositeBufferComponents = SETTING_HTTP_NETTY_MAX_COMPOSITE_BUFFER_COMPONENTS.get(settings);
209224
this.maxChunkSize = SETTING_HTTP_MAX_CHUNK_SIZE.get(settings);
210225
this.maxHeaderSize = SETTING_HTTP_MAX_HEADER_SIZE.get(settings);
226+
this.h2cMaxContentLength = SETTING_H2C_MAX_CONTENT_LENGTH.get(settings);
211227
this.maxInitialLineLength = SETTING_HTTP_MAX_INITIAL_LINE_LENGTH.get(settings);
212228
this.secureHttpTransportSettingsProvider = secureHttpTransportSettingsProvider;
213229
}
@@ -228,6 +244,7 @@ protected HttpServerChannel bind(InetSocketAddress socketAddress) throws Excepti
228244
.compress(true)
229245
.httpRequestDecoder(
230246
spec -> spec.maxChunkSize(maxChunkSize.bytesAsInt())
247+
.h2cMaxContentLength(h2cMaxContentLength.bytesAsInt())
231248
.maxHeaderSize(maxHeaderSize.bytesAsInt())
232249
.maxInitialLineLength(maxInitialLineLength.bytesAsInt())
233250
.allowPartialChunks(false)

plugins/transport-reactor-netty4/src/main/java/org/opensearch/transport/reactor/ReactorNetty4Plugin.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public ReactorNetty4Plugin() {}
5757
*/
5858
@Override
5959
public List<Setting<?>> getSettings() {
60-
return Arrays.asList(/* no setting registered since we're picking the onces from Netty 4 transport */);
60+
return Arrays.asList(ReactorNetty4HttpServerTransport.SETTING_H2C_MAX_CONTENT_LENGTH);
6161
}
6262

6363
/**

0 commit comments

Comments
 (0)