From 9a29b3f3740edf49f5f623657f205290cf9119a4 Mon Sep 17 00:00:00 2001 From: Alex Li Date: Wed, 19 Jun 2024 13:47:14 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=EF=B8=8F=20Sync=20implementation=20de?= =?UTF-8?q?tails?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../http2_adapter/lib/src/http2_adapter.dart | 58 ++++++++++--------- 1 file changed, 30 insertions(+), 28 deletions(-) diff --git a/plugins/http2_adapter/lib/src/http2_adapter.dart b/plugins/http2_adapter/lib/src/http2_adapter.dart index a118e3ff1..ad059ba25 100644 --- a/plugins/http2_adapter/lib/src/http2_adapter.dart +++ b/plugins/http2_adapter/lib/src/http2_adapter.dart @@ -50,32 +50,42 @@ class Http2Adapter implements HttpClientAdapter { RequestOptions options, Stream? requestStream, Future? cancelFuture, - ) async { + ) { // Recursive fetching. final redirects = []; - try { - final operation = CancelableOperation.fromFuture( - _fetch(options, requestStream, cancelFuture, redirects), - ); + final operation = CancelableOperation.fromFuture( + _fetch(options, requestStream, cancelFuture, redirects), + ); - if (cancelFuture != null) { - cancelFutureOperationPool.putIfAbsent(cancelFuture, () => {}); - cancelFutureRequestPool.putIfAbsent(cancelFuture, () => {}); + if (cancelFuture != null) { + cancelFutureOperationPool.putIfAbsent(cancelFuture, () => {}); + cancelFutureRequestPool.putIfAbsent(cancelFuture, () => {}); - cancelFuture.whenComplete(() { - cancelFutureOperationPool[cancelFuture]?.forEach((e) => e.cancel()); - cancelFutureOperationPool.remove(cancelFuture); - cancelFutureRequestPool[cancelFuture] - ?.forEach((e) => e.outgoingMessages.close()); - cancelFutureRequestPool.remove(cancelFuture); - }); + cancelFuture.whenComplete(() { + cancelFutureOperationPool[cancelFuture]?.forEach((e) => e.cancel()); + cancelFutureOperationPool.remove(cancelFuture); + cancelFutureRequestPool[cancelFuture] + ?.forEach((e) => e.outgoingMessages.close()); + cancelFutureRequestPool.remove(cancelFuture); + }); - cancelFutureOperationPool[cancelFuture]!.add(operation); - } + cancelFutureOperationPool[cancelFuture]!.add(operation); + } - return operation.value.whenComplete( - () => cancelFutureOperationPool[cancelFuture]?.remove(operation), - ); + return operation.value.whenComplete( + () => cancelFutureOperationPool[cancelFuture]?.remove(operation), + ); + } + + Future _fetch( + RequestOptions options, + Stream? requestStream, + Future? cancelFuture, + List redirects, + ) async { + late final ClientTransportConnection transport; + try { + transport = await connectionManager.getConnection(options); } on DioH2NotSupportedException catch (e) { // Fallback to use the callback // or to another adapter (typically IOHttpClientAdapter) @@ -105,15 +115,7 @@ class Http2Adapter implements HttpClientAdapter { error: e, ); } - } - Future _fetch( - RequestOptions options, - Stream? requestStream, - Future? cancelFuture, - List redirects, - ) async { - final transport = await connectionManager.getConnection(options); final uri = options.uri; String path = uri.path; const excludeMethods = ['PUT', 'POST', 'PATCH'];