336 // set callbacks before sending preface - makes sure anything that 337 // might be sent by the server will come our way. 338 this.initial = initial; 339 connectFlows(connection); 340 sendConnectionPreface(); 341 } 342 343 // Used when upgrading an HTTP/1.1 connection to HTTP/2 after receiving 344 // agreement from the server. Async style but completes immediately, because 345 // the connection is already connected. 346 static CompletableFuture<Http2Connection> createAsync(HttpConnection connection, 347 Http2ClientImpl client2, 348 Exchange<?> exchange, 349 Supplier<ByteBuffer> initial) 350 { 351 return MinimalFuture.supply(() -> new Http2Connection(connection, client2, exchange, initial)); 352 } 353 354 // Requires TLS handshake. So, is really async 355 static CompletableFuture<Http2Connection> createAsync(HttpRequestImpl request, 356 Http2ClientImpl h2client) { 357 assert request.secure(); 358 AbstractAsyncSSLConnection connection = (AbstractAsyncSSLConnection) 359 HttpConnection.getConnection(request.getAddress(), 360 h2client.client(), 361 request, 362 HttpClient.Version.HTTP_2); 363 364 return connection.connectAsync() 365 .thenCompose(unused -> checkSSLConfig(connection)) 366 .thenCompose(notused-> { 367 CompletableFuture<Http2Connection> cf = new MinimalFuture<>(); 368 try { 369 Http2Connection hc = new Http2Connection(request, h2client, connection); 370 cf.complete(hc); 371 } catch (IOException e) { 372 cf.completeExceptionally(e); 373 } 374 return cf; } ); 375 } 376 377 /** 378 * Cases 2) 3) 379 * 380 * request is request to be sent. 381 */ 382 private Http2Connection(HttpRequestImpl request, 383 Http2ClientImpl h2client, 384 HttpConnection connection) | 336 // set callbacks before sending preface - makes sure anything that 337 // might be sent by the server will come our way. 338 this.initial = initial; 339 connectFlows(connection); 340 sendConnectionPreface(); 341 } 342 343 // Used when upgrading an HTTP/1.1 connection to HTTP/2 after receiving 344 // agreement from the server. Async style but completes immediately, because 345 // the connection is already connected. 346 static CompletableFuture<Http2Connection> createAsync(HttpConnection connection, 347 Http2ClientImpl client2, 348 Exchange<?> exchange, 349 Supplier<ByteBuffer> initial) 350 { 351 return MinimalFuture.supply(() -> new Http2Connection(connection, client2, exchange, initial)); 352 } 353 354 // Requires TLS handshake. So, is really async 355 static CompletableFuture<Http2Connection> createAsync(HttpRequestImpl request, 356 Http2ClientImpl h2client, 357 Exchange<?> exchange) { 358 assert request.secure(); 359 AbstractAsyncSSLConnection connection = (AbstractAsyncSSLConnection) 360 HttpConnection.getConnection(request.getAddress(), 361 h2client.client(), 362 request, 363 HttpClient.Version.HTTP_2); 364 365 // Expose the underlying connection to the exchange's aborter so it can 366 // be closed if a timeout occurs. 367 exchange.connectionAborter.connection(connection); 368 369 return connection.connectAsync(exchange) 370 .thenCompose(unused -> connection.finishConnect()) 371 .thenCompose(unused -> checkSSLConfig(connection)) 372 .thenCompose(notused-> { 373 CompletableFuture<Http2Connection> cf = new MinimalFuture<>(); 374 try { 375 Http2Connection hc = new Http2Connection(request, h2client, connection); 376 cf.complete(hc); 377 } catch (IOException e) { 378 cf.completeExceptionally(e); 379 } 380 return cf; } ); 381 } 382 383 /** 384 * Cases 2) 3) 385 * 386 * request is request to be sent. 387 */ 388 private Http2Connection(HttpRequestImpl request, 389 Http2ClientImpl h2client, 390 HttpConnection connection) |