|
22 | 22 | import io.airlift.http.server.jetty.MonitoredQueuedThreadPoolMBean;
|
23 | 23 | import io.airlift.log.Logger;
|
24 | 24 | import io.airlift.node.NodeInfo;
|
| 25 | +import io.airlift.units.DataSize; |
25 | 26 | import jakarta.annotation.PostConstruct;
|
26 | 27 | import jakarta.annotation.PreDestroy;
|
27 | 28 | import jakarta.servlet.Filter;
|
|
34 | 35 | import org.eclipse.jetty.http2.server.AuthorityCustomizer;
|
35 | 36 | import org.eclipse.jetty.http2.server.HTTP2CServerConnectionFactory;
|
36 | 37 | import org.eclipse.jetty.http2.server.HTTP2ServerConnectionFactory;
|
| 38 | +import org.eclipse.jetty.io.ArrayByteBufferPool; |
| 39 | +import org.eclipse.jetty.io.ByteBufferPool; |
37 | 40 | import org.eclipse.jetty.io.ConnectionStatistics;
|
38 | 41 | import org.eclipse.jetty.jmx.MBeanContainer;
|
39 | 42 | import org.eclipse.jetty.server.ConnectionFactory;
|
|
65 | 68 | import java.util.EnumSet;
|
66 | 69 | import java.util.List;
|
67 | 70 | import java.util.Optional;
|
| 71 | +import java.util.OptionalLong; |
68 | 72 | import java.util.Set;
|
69 | 73 | import java.util.concurrent.Executor;
|
70 | 74 | import java.util.concurrent.ScheduledExecutorService;
|
|
75 | 79 | import static com.google.common.base.Verify.verify;
|
76 | 80 | import static com.google.common.collect.ImmutableList.toImmutableList;
|
77 | 81 | import static io.airlift.concurrent.Threads.daemonThreadsNamed;
|
| 82 | +import static java.lang.Math.max; |
78 | 83 | import static java.lang.Math.toIntExact;
|
79 | 84 | import static java.time.temporal.ChronoUnit.DAYS;
|
80 | 85 | import static java.util.Collections.list;
|
@@ -140,7 +145,12 @@ public HttpServer(
|
140 | 145 | log.info("Virtual threads support is enabled");
|
141 | 146 | threadPool.setVirtualThreadsExecutor(executor);
|
142 | 147 | }
|
143 |
| - server = new Server(threadPool); |
| 148 | + |
| 149 | + int maxBufferSize = toIntExact(max( |
| 150 | + toSafeBytes(config.getMaxRequestHeaderSize()).orElse(65536), |
| 151 | + toSafeBytes(config.getMaxResponseHeaderSize()).orElse(65536))); |
| 152 | + |
| 153 | + server = new Server(threadPool, null, createByteBufferPool(maxBufferSize, config)); |
144 | 154 | this.monitoredQueuedThreadPoolMBean = new MonitoredQueuedThreadPoolMBean(threadPool);
|
145 | 155 |
|
146 | 156 | boolean showStackTrace = config.isShowStackTrace();
|
@@ -274,14 +284,25 @@ public HttpServer(
|
274 | 284 | }
|
275 | 285 |
|
276 | 286 | server.setHandler(statsHandler);
|
277 |
| - |
278 | 287 | ErrorHandler errorHandler = new ErrorHandler();
|
279 | 288 | errorHandler.setShowMessageInTitle(showStackTrace);
|
280 | 289 | errorHandler.setShowStacks(showStackTrace);
|
281 | 290 | errorHandler.setDefaultResponseMimeType(TEXT_PLAIN.asString());
|
282 | 291 | server.setErrorHandler(errorHandler);
|
283 | 292 | }
|
284 | 293 |
|
| 294 | + private ByteBufferPool createByteBufferPool(int maxBufferSize, HttpServerConfig config) |
| 295 | + { |
| 296 | + return new ArrayByteBufferPool.Quadratic( |
| 297 | + 0, |
| 298 | + maxBufferSize, |
| 299 | + Integer.MAX_VALUE, |
| 300 | + config.getMaxHeapMemory().map(DataSize::toBytes) |
| 301 | + .orElse(0L), // Use default heuristics for max heap memory |
| 302 | + config.getMaxDirectMemory().map(DataSize::toBytes) |
| 303 | + .orElse(0L)); // Use default heuristics for max direct memory |
| 304 | + } |
| 305 | + |
285 | 306 | private ConnectionFactory[] insecureFactories(HttpServerConfig config, HttpConfiguration httpConfiguration)
|
286 | 307 | {
|
287 | 308 | HttpConnectionFactory http1 = new HttpConnectionFactory(httpConfiguration);
|
@@ -473,4 +494,13 @@ private static ServerConnector createServerConnector(
|
473 | 494 | connector.open(channel);
|
474 | 495 | return connector;
|
475 | 496 | }
|
| 497 | + |
| 498 | + private static OptionalLong toSafeBytes(DataSize dataSize) |
| 499 | + { |
| 500 | + if (dataSize == null) { |
| 501 | + return OptionalLong.empty(); |
| 502 | + } |
| 503 | + |
| 504 | + return OptionalLong.of(dataSize.toBytes()); |
| 505 | + } |
476 | 506 | }
|
0 commit comments