68 /**
69 * Returns the {@link HttpConnection} instance to which this exchange is
70 * assigned.
71 */
72 abstract HttpConnection connection();
73
74 /**
75 * Initiates a new exchange and assigns it to a connection if one exists
76 * already. connection usually null.
77 */
78 static <U> CompletableFuture<? extends ExchangeImpl<U>>
79 get(Exchange<U> exchange, HttpConnection connection)
80 {
81 if (exchange.version() == HTTP_1_1) {
82 if (debug.on())
83 debug.log("get: HTTP/1.1: new Http1Exchange");
84 return createHttp1Exchange(exchange, connection);
85 } else {
86 Http2ClientImpl c2 = exchange.client().client2(); // #### improve
87 HttpRequestImpl request = exchange.request();
88 CompletableFuture<Http2Connection> c2f = c2.getConnectionFor(request);
89 if (debug.on())
90 debug.log("get: Trying to get HTTP/2 connection");
91 return c2f.handle((h2c, t) -> createExchangeImpl(h2c, t, exchange, connection))
92 .thenCompose(Function.identity());
93 }
94 }
95
96 private static <U> CompletableFuture<? extends ExchangeImpl<U>>
97 createExchangeImpl(Http2Connection c,
98 Throwable t,
99 Exchange<U> exchange,
100 HttpConnection connection)
101 {
102 if (debug.on())
103 debug.log("handling HTTP/2 connection creation result");
104 boolean secure = exchange.request().secure();
105 if (t != null) {
106 if (debug.on())
107 debug.log("handling HTTP/2 connection creation failed: %s",
108 (Object)t);
|
68 /**
69 * Returns the {@link HttpConnection} instance to which this exchange is
70 * assigned.
71 */
72 abstract HttpConnection connection();
73
74 /**
75 * Initiates a new exchange and assigns it to a connection if one exists
76 * already. connection usually null.
77 */
78 static <U> CompletableFuture<? extends ExchangeImpl<U>>
79 get(Exchange<U> exchange, HttpConnection connection)
80 {
81 if (exchange.version() == HTTP_1_1) {
82 if (debug.on())
83 debug.log("get: HTTP/1.1: new Http1Exchange");
84 return createHttp1Exchange(exchange, connection);
85 } else {
86 Http2ClientImpl c2 = exchange.client().client2(); // #### improve
87 HttpRequestImpl request = exchange.request();
88 CompletableFuture<Http2Connection> c2f = c2.getConnectionFor(request, exchange);
89 if (debug.on())
90 debug.log("get: Trying to get HTTP/2 connection");
91 return c2f.handle((h2c, t) -> createExchangeImpl(h2c, t, exchange, connection))
92 .thenCompose(Function.identity());
93 }
94 }
95
96 private static <U> CompletableFuture<? extends ExchangeImpl<U>>
97 createExchangeImpl(Http2Connection c,
98 Throwable t,
99 Exchange<U> exchange,
100 HttpConnection connection)
101 {
102 if (debug.on())
103 debug.log("handling HTTP/2 connection creation result");
104 boolean secure = exchange.request().secure();
105 if (t != null) {
106 if (debug.on())
107 debug.log("handling HTTP/2 connection creation failed: %s",
108 (Object)t);
|