Skip to content

Commit

Permalink
Add SETTING_H2C_MAX_CONTENT_LENGTH to configure h2cMaxContentLength f…
Browse files Browse the repository at this point in the history
…or reactor-netty4 transport

Signed-off-by: Andriy Redko <[email protected]>
  • Loading branch information
reta committed Jan 14, 2025
1 parent 3de626a commit b466fb8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.opensearch.common.util.concurrent.OpenSearchExecutors;
import org.opensearch.common.util.io.IOUtils;
import org.opensearch.common.util.net.NetUtils;
import org.opensearch.core.common.unit.ByteSizeUnit;
import org.opensearch.core.common.unit.ByteSizeValue;
import org.opensearch.core.xcontent.NamedXContentRegistry;
import org.opensearch.http.AbstractHttpServerTransport;
Expand Down Expand Up @@ -87,6 +88,19 @@ public class ReactorNetty4HttpServerTransport extends AbstractHttpServerTranspor
private static final String SETTING_KEY_HTTP_NETTY_MAX_COMPOSITE_BUFFER_COMPONENTS = "http.netty.max_composite_buffer_components";
private static final ByteSizeValue MTU = new ByteSizeValue(Long.parseLong(System.getProperty("opensearch.net.mtu", "1500")));

/**
* Configure the maximum length of the content of the HTTP/2.0 clear-text upgrade request.
* By default the server will reject an upgrade request with non-empty content,
* because the upgrade request is most likely a GET request. If the client sends
* a non-GET upgrade request, {@link #h2cMaxContentLength} specifies the maximum
* length of the content of the upgrade request.
*/
public static final Setting<ByteSizeValue> SETTING_H2C_MAX_CONTENT_LENGTH = Setting.byteSizeSetting(
"h2c.max_content_length",
new ByteSizeValue(65536, ByteSizeUnit.KB),
Property.NodeScope
);

/**
* The number of Reactor Netty HTTP workers
*/
Expand Down Expand Up @@ -133,6 +147,7 @@ public class ReactorNetty4HttpServerTransport extends AbstractHttpServerTranspor
private final ByteSizeValue maxInitialLineLength;
private final ByteSizeValue maxHeaderSize;
private final ByteSizeValue maxChunkSize;
private final ByteSizeValue h2cMaxContentLength;
private final SecureHttpTransportSettingsProvider secureHttpTransportSettingsProvider;
private volatile SharedGroupFactory.SharedGroup sharedGroup;
private volatile DisposableServer disposableServer;
Expand Down Expand Up @@ -208,6 +223,7 @@ public ReactorNetty4HttpServerTransport(
this.maxCompositeBufferComponents = SETTING_HTTP_NETTY_MAX_COMPOSITE_BUFFER_COMPONENTS.get(settings);
this.maxChunkSize = SETTING_HTTP_MAX_CHUNK_SIZE.get(settings);
this.maxHeaderSize = SETTING_HTTP_MAX_HEADER_SIZE.get(settings);
this.h2cMaxContentLength = SETTING_H2C_MAX_CONTENT_LENGTH.get(settings);
this.maxInitialLineLength = SETTING_HTTP_MAX_INITIAL_LINE_LENGTH.get(settings);
this.secureHttpTransportSettingsProvider = secureHttpTransportSettingsProvider;
}
Expand All @@ -228,6 +244,7 @@ protected HttpServerChannel bind(InetSocketAddress socketAddress) throws Excepti
.compress(true)
.httpRequestDecoder(
spec -> spec.maxChunkSize(maxChunkSize.bytesAsInt())
.h2cMaxContentLength(h2cMaxContentLength.bytesAsInt())
.maxHeaderSize(maxHeaderSize.bytesAsInt())
.maxInitialLineLength(maxInitialLineLength.bytesAsInt())
.allowPartialChunks(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public ReactorNetty4Plugin() {}
*/
@Override
public List<Setting<?>> getSettings() {
return Arrays.asList(/* no setting registered since we're picking the onces from Netty 4 transport */);
return Arrays.asList(ReactorNetty4HttpServerTransport.SETTING_H2C_MAX_CONTENT_LENGTH);
}

/**
Expand Down

0 comments on commit b466fb8

Please sign in to comment.