|
101 | 101 | import static org.asynchttpclient.config.AsyncHttpClientConfigDefaults.defaultUserAgent; |
102 | 102 | import static org.asynchttpclient.config.AsyncHttpClientConfigDefaults.defaultValidateResponseHeaders; |
103 | 103 | import static org.asynchttpclient.config.AsyncHttpClientConfigDefaults.defaultWebSocketMaxBufferSize; |
| 104 | +import static org.asynchttpclient.config.AsyncHttpClientConfigDefaults.defaultHttp2CleartextEnabled; |
| 105 | +import static org.asynchttpclient.config.AsyncHttpClientConfigDefaults.defaultHttp2HeaderTableSize; |
| 106 | +import static org.asynchttpclient.config.AsyncHttpClientConfigDefaults.defaultHttp2InitialWindowSize; |
| 107 | +import static org.asynchttpclient.config.AsyncHttpClientConfigDefaults.defaultHttp2MaxConcurrentStreams; |
| 108 | +import static org.asynchttpclient.config.AsyncHttpClientConfigDefaults.defaultHttp2MaxFrameSize; |
| 109 | +import static org.asynchttpclient.config.AsyncHttpClientConfigDefaults.defaultHttp2MaxHeaderListSize; |
| 110 | +import static org.asynchttpclient.config.AsyncHttpClientConfigDefaults.defaultHttp2PingInterval; |
104 | 111 | import static org.asynchttpclient.config.AsyncHttpClientConfigDefaults.defaultWebSocketMaxFrameSize; |
105 | 112 |
|
106 | 113 | /** |
@@ -166,6 +173,14 @@ public class DefaultAsyncHttpClientConfig implements AsyncHttpClientConfig { |
166 | 173 | private final int sslSessionTimeout; |
167 | 174 | private final @Nullable SslContext sslContext; |
168 | 175 | private final @Nullable SslEngineFactory sslEngineFactory; |
| 176 | + private final boolean http2Enabled; |
| 177 | + private final int http2InitialWindowSize; |
| 178 | + private final int http2MaxFrameSize; |
| 179 | + private final int http2HeaderTableSize; |
| 180 | + private final int http2MaxHeaderListSize; |
| 181 | + private final int http2MaxConcurrentStreams; |
| 182 | + private final Duration http2PingInterval; |
| 183 | + private final boolean http2CleartextEnabled; |
169 | 184 |
|
170 | 185 | // filters |
171 | 186 | private final List<RequestFilter> requestFilters; |
@@ -253,6 +268,14 @@ private DefaultAsyncHttpClientConfig(// http |
253 | 268 | int sslSessionTimeout, |
254 | 269 | @Nullable SslContext sslContext, |
255 | 270 | @Nullable SslEngineFactory sslEngineFactory, |
| 271 | + boolean http2Enabled, |
| 272 | + int http2InitialWindowSize, |
| 273 | + int http2MaxFrameSize, |
| 274 | + int http2HeaderTableSize, |
| 275 | + int http2MaxHeaderListSize, |
| 276 | + int http2MaxConcurrentStreams, |
| 277 | + Duration http2PingInterval, |
| 278 | + boolean http2CleartextEnabled, |
256 | 279 |
|
257 | 280 | // filters |
258 | 281 | List<RequestFilter> requestFilters, |
@@ -348,6 +371,14 @@ private DefaultAsyncHttpClientConfig(// http |
348 | 371 | this.sslSessionTimeout = sslSessionTimeout; |
349 | 372 | this.sslContext = sslContext; |
350 | 373 | this.sslEngineFactory = sslEngineFactory; |
| 374 | + this.http2Enabled = http2Enabled; |
| 375 | + this.http2InitialWindowSize = http2InitialWindowSize; |
| 376 | + this.http2MaxFrameSize = http2MaxFrameSize; |
| 377 | + this.http2HeaderTableSize = http2HeaderTableSize; |
| 378 | + this.http2MaxHeaderListSize = http2MaxHeaderListSize; |
| 379 | + this.http2MaxConcurrentStreams = http2MaxConcurrentStreams; |
| 380 | + this.http2PingInterval = http2PingInterval; |
| 381 | + this.http2CleartextEnabled = http2CleartextEnabled; |
351 | 382 |
|
352 | 383 | // filters |
353 | 384 | this.requestFilters = requestFilters; |
@@ -382,6 +413,14 @@ private DefaultAsyncHttpClientConfig(// http |
382 | 413 | throw new IllegalArgumentException("Native Transport must be enabled to use Epoll Native Transport only"); |
383 | 414 | } |
384 | 415 |
|
| 416 | + if (http2MaxFrameSize < 16384 || http2MaxFrameSize > 16777215) { |
| 417 | + throw new IllegalArgumentException("HTTP/2 max frame size must be between 16384 and 16777215 per RFC 7540 §4.2"); |
| 418 | + } |
| 419 | + |
| 420 | + if (http2InitialWindowSize < 0) { |
| 421 | + throw new IllegalArgumentException("HTTP/2 initial window size must be non-negative"); |
| 422 | + } |
| 423 | + |
385 | 424 | this.allocator = allocator; |
386 | 425 | this.nettyTimer = nettyTimer; |
387 | 426 | this.threadFactory = threadFactory; |
@@ -608,6 +647,46 @@ public boolean isFilterInsecureCipherSuites() { |
608 | 647 | return filterInsecureCipherSuites; |
609 | 648 | } |
610 | 649 |
|
| 650 | + @Override |
| 651 | + public boolean isHttp2Enabled() { |
| 652 | + return http2Enabled; |
| 653 | + } |
| 654 | + |
| 655 | + @Override |
| 656 | + public int getHttp2InitialWindowSize() { |
| 657 | + return http2InitialWindowSize; |
| 658 | + } |
| 659 | + |
| 660 | + @Override |
| 661 | + public int getHttp2MaxFrameSize() { |
| 662 | + return http2MaxFrameSize; |
| 663 | + } |
| 664 | + |
| 665 | + @Override |
| 666 | + public int getHttp2HeaderTableSize() { |
| 667 | + return http2HeaderTableSize; |
| 668 | + } |
| 669 | + |
| 670 | + @Override |
| 671 | + public int getHttp2MaxHeaderListSize() { |
| 672 | + return http2MaxHeaderListSize; |
| 673 | + } |
| 674 | + |
| 675 | + @Override |
| 676 | + public int getHttp2MaxConcurrentStreams() { |
| 677 | + return http2MaxConcurrentStreams; |
| 678 | + } |
| 679 | + |
| 680 | + @Override |
| 681 | + public Duration getHttp2PingInterval() { |
| 682 | + return http2PingInterval; |
| 683 | + } |
| 684 | + |
| 685 | + @Override |
| 686 | + public boolean isHttp2CleartextEnabled() { |
| 687 | + return http2CleartextEnabled; |
| 688 | + } |
| 689 | + |
611 | 690 | @Override |
612 | 691 | public int getSslSessionCacheSize() { |
613 | 692 | return sslSessionCacheSize; |
@@ -847,6 +926,14 @@ public static class Builder { |
847 | 926 | private int sslSessionTimeout = defaultSslSessionTimeout(); |
848 | 927 | private @Nullable SslContext sslContext; |
849 | 928 | private @Nullable SslEngineFactory sslEngineFactory; |
| 929 | + private boolean http2Enabled = true; |
| 930 | + private int http2InitialWindowSize = defaultHttp2InitialWindowSize(); |
| 931 | + private int http2MaxFrameSize = defaultHttp2MaxFrameSize(); |
| 932 | + private int http2HeaderTableSize = defaultHttp2HeaderTableSize(); |
| 933 | + private int http2MaxHeaderListSize = defaultHttp2MaxHeaderListSize(); |
| 934 | + private int http2MaxConcurrentStreams = defaultHttp2MaxConcurrentStreams(); |
| 935 | + private Duration http2PingInterval = defaultHttp2PingInterval(); |
| 936 | + private boolean http2CleartextEnabled = defaultHttp2CleartextEnabled(); |
850 | 937 |
|
851 | 938 | // cookie store |
852 | 939 | private CookieStore cookieStore = new ThreadSafeCookieStore(); |
@@ -939,6 +1026,14 @@ public Builder(AsyncHttpClientConfig config) { |
939 | 1026 | sslSessionTimeout = config.getSslSessionTimeout(); |
940 | 1027 | sslContext = config.getSslContext(); |
941 | 1028 | sslEngineFactory = config.getSslEngineFactory(); |
| 1029 | + http2Enabled = config.isHttp2Enabled(); |
| 1030 | + http2InitialWindowSize = config.getHttp2InitialWindowSize(); |
| 1031 | + http2MaxFrameSize = config.getHttp2MaxFrameSize(); |
| 1032 | + http2HeaderTableSize = config.getHttp2HeaderTableSize(); |
| 1033 | + http2MaxHeaderListSize = config.getHttp2MaxHeaderListSize(); |
| 1034 | + http2MaxConcurrentStreams = config.getHttp2MaxConcurrentStreams(); |
| 1035 | + http2PingInterval = config.getHttp2PingInterval(); |
| 1036 | + http2CleartextEnabled = config.isHttp2CleartextEnabled(); |
942 | 1037 |
|
943 | 1038 | // filters |
944 | 1039 | requestFilters.addAll(config.getRequestFilters()); |
@@ -1254,6 +1349,46 @@ public Builder setSslEngineFactory(SslEngineFactory sslEngineFactory) { |
1254 | 1349 | return this; |
1255 | 1350 | } |
1256 | 1351 |
|
| 1352 | + public Builder setHttp2Enabled(boolean http2Enabled) { |
| 1353 | + this.http2Enabled = http2Enabled; |
| 1354 | + return this; |
| 1355 | + } |
| 1356 | + |
| 1357 | + public Builder setHttp2InitialWindowSize(int http2InitialWindowSize) { |
| 1358 | + this.http2InitialWindowSize = http2InitialWindowSize; |
| 1359 | + return this; |
| 1360 | + } |
| 1361 | + |
| 1362 | + public Builder setHttp2MaxFrameSize(int http2MaxFrameSize) { |
| 1363 | + this.http2MaxFrameSize = http2MaxFrameSize; |
| 1364 | + return this; |
| 1365 | + } |
| 1366 | + |
| 1367 | + public Builder setHttp2HeaderTableSize(int http2HeaderTableSize) { |
| 1368 | + this.http2HeaderTableSize = http2HeaderTableSize; |
| 1369 | + return this; |
| 1370 | + } |
| 1371 | + |
| 1372 | + public Builder setHttp2MaxHeaderListSize(int http2MaxHeaderListSize) { |
| 1373 | + this.http2MaxHeaderListSize = http2MaxHeaderListSize; |
| 1374 | + return this; |
| 1375 | + } |
| 1376 | + |
| 1377 | + public Builder setHttp2MaxConcurrentStreams(int http2MaxConcurrentStreams) { |
| 1378 | + this.http2MaxConcurrentStreams = http2MaxConcurrentStreams; |
| 1379 | + return this; |
| 1380 | + } |
| 1381 | + |
| 1382 | + public Builder setHttp2PingInterval(Duration http2PingInterval) { |
| 1383 | + this.http2PingInterval = http2PingInterval; |
| 1384 | + return this; |
| 1385 | + } |
| 1386 | + |
| 1387 | + public Builder setHttp2CleartextEnabled(boolean http2CleartextEnabled) { |
| 1388 | + this.http2CleartextEnabled = http2CleartextEnabled; |
| 1389 | + return this; |
| 1390 | + } |
| 1391 | + |
1257 | 1392 | // filters |
1258 | 1393 | public Builder addRequestFilter(RequestFilter requestFilter) { |
1259 | 1394 | requestFilters.add(requestFilter); |
@@ -1486,6 +1621,14 @@ public DefaultAsyncHttpClientConfig build() { |
1486 | 1621 | sslSessionTimeout, |
1487 | 1622 | sslContext, |
1488 | 1623 | sslEngineFactory, |
| 1624 | + http2Enabled, |
| 1625 | + http2InitialWindowSize, |
| 1626 | + http2MaxFrameSize, |
| 1627 | + http2HeaderTableSize, |
| 1628 | + http2MaxHeaderListSize, |
| 1629 | + http2MaxConcurrentStreams, |
| 1630 | + http2PingInterval, |
| 1631 | + http2CleartextEnabled, |
1489 | 1632 | requestFilters.isEmpty() ? Collections.emptyList() : Collections.unmodifiableList(requestFilters), |
1490 | 1633 | responseFilters.isEmpty() ? Collections.emptyList() : Collections.unmodifiableList(responseFilters), |
1491 | 1634 | ioExceptionFilters.isEmpty() ? Collections.emptyList() : Collections.unmodifiableList(ioExceptionFilters), |
|
0 commit comments