18
18
import org .opensearch .common .util .concurrent .OpenSearchExecutors ;
19
19
import org .opensearch .common .util .io .IOUtils ;
20
20
import org .opensearch .common .util .net .NetUtils ;
21
+ import org .opensearch .core .common .unit .ByteSizeUnit ;
21
22
import org .opensearch .core .common .unit .ByteSizeValue ;
22
23
import org .opensearch .core .xcontent .NamedXContentRegistry ;
23
24
import org .opensearch .http .AbstractHttpServerTransport ;
@@ -87,6 +88,19 @@ public class ReactorNetty4HttpServerTransport extends AbstractHttpServerTranspor
87
88
private static final String SETTING_KEY_HTTP_NETTY_MAX_COMPOSITE_BUFFER_COMPONENTS = "http.netty.max_composite_buffer_components" ;
88
89
private static final ByteSizeValue MTU = new ByteSizeValue (Long .parseLong (System .getProperty ("opensearch.net.mtu" , "1500" )));
89
90
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
+
90
104
/**
91
105
* The number of Reactor Netty HTTP workers
92
106
*/
@@ -133,6 +147,7 @@ public class ReactorNetty4HttpServerTransport extends AbstractHttpServerTranspor
133
147
private final ByteSizeValue maxInitialLineLength ;
134
148
private final ByteSizeValue maxHeaderSize ;
135
149
private final ByteSizeValue maxChunkSize ;
150
+ private final ByteSizeValue h2cMaxContentLength ;
136
151
private final SecureHttpTransportSettingsProvider secureHttpTransportSettingsProvider ;
137
152
private volatile SharedGroupFactory .SharedGroup sharedGroup ;
138
153
private volatile DisposableServer disposableServer ;
@@ -208,6 +223,7 @@ public ReactorNetty4HttpServerTransport(
208
223
this .maxCompositeBufferComponents = SETTING_HTTP_NETTY_MAX_COMPOSITE_BUFFER_COMPONENTS .get (settings );
209
224
this .maxChunkSize = SETTING_HTTP_MAX_CHUNK_SIZE .get (settings );
210
225
this .maxHeaderSize = SETTING_HTTP_MAX_HEADER_SIZE .get (settings );
226
+ this .h2cMaxContentLength = SETTING_H2C_MAX_CONTENT_LENGTH .get (settings );
211
227
this .maxInitialLineLength = SETTING_HTTP_MAX_INITIAL_LINE_LENGTH .get (settings );
212
228
this .secureHttpTransportSettingsProvider = secureHttpTransportSettingsProvider ;
213
229
}
@@ -228,6 +244,7 @@ protected HttpServerChannel bind(InetSocketAddress socketAddress) throws Excepti
228
244
.compress (true )
229
245
.httpRequestDecoder (
230
246
spec -> spec .maxChunkSize (maxChunkSize .bytesAsInt ())
247
+ .h2cMaxContentLength (h2cMaxContentLength .bytesAsInt ())
231
248
.maxHeaderSize (maxHeaderSize .bytesAsInt ())
232
249
.maxInitialLineLength (maxInitialLineLength .bytesAsInt ())
233
250
.allowPartialChunks (false )
0 commit comments