changeset: 48573:3f9dda0428dc http-client-branch
authormichaelm
Fri, 15 Dec 2017 14:26:23 +0000
branchhttp-client-branch
changeset 55993 087a6b6d4955
parent 55992 10cefe168d6d
child 56008 bbd688c6fbbb
changeset: 48573:3f9dda0428dc branch: http-client-branch tag: tip user: michaelm date: Fri Dec 15 14:19:51 2017 +0000 summary: http-client-branch: Fixed problem with h2c connection reuse.
src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/ExchangeImpl.java
--- a/src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/ExchangeImpl.java	Fri Dec 15 13:35:56 2017 +0300
+++ b/src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/ExchangeImpl.java	Fri Dec 15 14:26:23 2017 +0000
@@ -98,12 +98,12 @@
                        HttpConnection connection)
     {
         DEBUG_LOGGER.log(Level.DEBUG, "handling HTTP/2 connection creation result");
+        boolean secure = exchange.request().secure();
         if (t != null) {
             DEBUG_LOGGER.log(Level.DEBUG,
                              "handling HTTP/2 connection creation failed: %s",
                              (Object)t);
             t = Utils.getCompletionCause(t);
-            boolean secure = exchange.request().secure();
             if (t instanceof Http2Connection.ALPNException) {
                 Http2Connection.ALPNException ee = (Http2Connection.ALPNException)t;
                 AbstractAsyncSSLConnection as = ee.getConnection();
@@ -111,17 +111,18 @@
                 CompletableFuture<? extends ExchangeImpl<U>> ex =
                         createHttp1Exchange(exchange, as);
                 return ex;
-            } else if (secure && c== null) {
-                DEBUG_LOGGER.log(Level.DEBUG, "downgrading to HTTP/1.1 ");
-                CompletableFuture<? extends ExchangeImpl<U>> ex =
-                        createHttp1Exchange(exchange, null);
-                return ex;
             } else {
                 DEBUG_LOGGER.log(Level.DEBUG, "HTTP/2 connection creation failed "
                                   + "with unexpected exception: %s", (Object)t);
                 return CompletableFuture.failedFuture(t);
             }
         }
+        if (secure && c== null) {
+            DEBUG_LOGGER.log(Level.DEBUG, "downgrading to HTTP/1.1 ");
+            CompletableFuture<? extends ExchangeImpl<U>> ex =
+                    createHttp1Exchange(exchange, null);
+            return ex;
+        }
         if (c == null) {
             // no existing connection. Send request with HTTP 1 and then
             // upgrade if successful