Skip to content

Commit b32887d

Browse files
committed
Allow zero HTTP/2 keep-alive timeout
Motivation: Http2ClientConfig#setKeepAliveTimeout(Duration.ZERO) throws, although zero and null are documented as no timeout. HTTP/1 and HTTP/3 client configs already accept zero. Changes: Allow zero for HTTP/2 keep-alive timeout and add a regression test. Signed-off-by: Jihun Kim <shblue21@naver.com>
1 parent 86203ec commit b32887d

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

vertx-core/src/main/java/io/vertx/core/http/Http2ClientConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public Duration getKeepAliveTimeout() {
119119
* @return a reference to this, so the API can be used fluently
120120
*/
121121
public Http2ClientConfig setKeepAliveTimeout(Duration keepAliveTimeout) {
122-
if (keepAliveTimeout != null && (keepAliveTimeout.isNegative() || keepAliveTimeout.isZero())) {
122+
if (keepAliveTimeout != null && (keepAliveTimeout.isNegative())) {
123123
throw new IllegalArgumentException("HTTP/2 keepAliveTimeout must be >= 0");
124124
}
125125
this.keepAliveTimeout = keepAliveTimeout;

vertx-core/src/test/java/io/vertx/tests/http/HttpClientConfigTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212

1313
import io.vertx.core.http.HttpClientOptions;
1414
import io.vertx.core.http.HttpClientConfig;
15+
import io.vertx.core.http.Http2ClientConfig;
1516
import org.junit.Test;
1617

18+
import java.time.Duration;
1719
import java.util.List;
1820

1921
import static io.vertx.core.http.HttpVersion.*;
@@ -60,4 +62,12 @@ public void testFromHttp1_0Options() {
6062
assertFalse(config.isSsl());
6163
assertEquals(List.of(HTTP_1_0), config.getVersions());
6264
}
65+
66+
@Test
67+
public void testHttp2KeepAliveTimeoutValidation() {
68+
Http2ClientConfig config = new Http2ClientConfig();
69+
assertSame(config, config.setKeepAliveTimeout(Duration.ZERO));
70+
assertEquals(Duration.ZERO, config.getKeepAliveTimeout());
71+
assertThrows(IllegalArgumentException.class, () -> config.setKeepAliveTimeout(Duration.ofMillis(-1)));
72+
}
6373
}

0 commit comments

Comments
 (0)