--- old/src/java.net.http/share/classes/jdk/internal/net/http/HttpClientImpl.java 2018-08-07 15:13:42.000000000 +0100 +++ new/src/java.net.http/share/classes/jdk/internal/net/http/HttpClientImpl.java 2018-08-07 15:13:42.000000000 +0100 @@ -35,6 +35,7 @@ import java.net.ConnectException; import java.net.CookieHandler; import java.net.ProxySelector; +import java.net.http.HttpConnectTimeoutException; import java.net.http.HttpTimeoutException; import java.nio.ByteBuffer; import java.nio.channels.CancelledKeyException; @@ -47,6 +48,7 @@ import java.security.AccessController; import java.security.NoSuchAlgorithmException; import java.security.PrivilegedAction; +import java.time.Duration; import java.time.Instant; import java.time.temporal.ChronoUnit; import java.util.ArrayList; @@ -154,6 +156,7 @@ } private final CookieHandler cookieHandler; + private final Duration connectTimeout; private final Redirect followRedirects; private final Optional userProxySelector; private final ProxySelector proxySelector; @@ -278,6 +281,7 @@ facadeRef = new WeakReference<>(facadeFactory.createFacade(this)); client2 = new Http2ClientImpl(this); cookieHandler = builder.cookieHandler; + connectTimeout = builder.connectTimeout; followRedirects = builder.followRedirects == null ? Redirect.NEVER : builder.followRedirects; this.userProxySelector = Optional.ofNullable(builder.proxy); @@ -547,6 +551,10 @@ throw new IllegalArgumentException(msg, throwable); } else if (throwable instanceof SecurityException) { throw new SecurityException(msg, throwable); + } else if (throwable instanceof HttpConnectTimeoutException) { + HttpConnectTimeoutException hcte = new HttpConnectTimeoutException(msg); + hcte.initCause(throwable); + throw hcte; } else if (throwable instanceof HttpTimeoutException) { throw new HttpTimeoutException(msg); } else if (throwable instanceof ConnectException) { @@ -1124,6 +1132,11 @@ } @Override + public Optional connectTimeout() { + return Optional.ofNullable(connectTimeout); + } + + @Override public Optional proxy() { return this.userProxySelector; }