--- old/src/java.net.http/share/classes/jdk/internal/net/http/AsyncSSLConnection.java 2018-08-07 15:13:08.000000000 +0100 +++ new/src/java.net.http/share/classes/jdk/internal/net/http/AsyncSSLConnection.java 2018-08-07 15:13:07.000000000 +0100 @@ -28,6 +28,8 @@ import java.net.InetSocketAddress; import java.nio.channels.SocketChannel; import java.util.concurrent.CompletableFuture; +import java.util.function.Function; +import jdk.internal.net.http.common.MinimalFuture; import jdk.internal.net.http.common.SSLTube; import jdk.internal.net.http.common.Utils; @@ -49,14 +51,9 @@ } @Override - PlainHttpConnection plainConnection() { - return plainConnection; - } - - @Override - public CompletableFuture connectAsync() { + public CompletableFuture connectAsync(Exchange exchange) { return plainConnection - .connectAsync() + .connectAsync(exchange) .thenApply( unused -> { // create the SSLTube wrapping the SocketTube, with the given engine flow = new SSLTube(engine, @@ -67,6 +64,21 @@ } @Override + public CompletableFuture finishConnect() { + // The actual ALPN value, which may be the empty string, is not + // interesting at this point, only that the handshake has completed. + return getALPN() + .handle((String unused, Throwable ex) -> { + if (ex == null) { + return plainConnection.finishConnect(); + } else { + plainConnection.close(); + return MinimalFuture.failedFuture(ex); + } }) + .thenCompose(Function.identity()); + } + + @Override boolean connected() { return plainConnection.connected(); }