From 945d4879f8d316ce29c38f12eef40a19d6e413ef Mon Sep 17 00:00:00 2001 From: Alex Li Date: Mon, 7 Oct 2024 13:58:01 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A5=20Remove=20redundant=20warnings=20?= =?UTF-8?q?(#2309)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes https://github.com/cfug/dio/discussions/2306 The warning will be raised within the adapter. --- dio/CHANGELOG.md | 7 +++---- dio/lib/src/options.dart | 14 -------------- plugins/web_adapter/lib/src/adapter.dart | 9 +++++---- 3 files changed, 8 insertions(+), 22 deletions(-) diff --git a/dio/CHANGELOG.md b/dio/CHANGELOG.md index e319e0ed4..3ff5268d3 100644 --- a/dio/CHANGELOG.md +++ b/dio/CHANGELOG.md @@ -5,13 +5,12 @@ See the [Migration Guide][] for the complete breaking changes list.** ## Unreleased -*None.* +- Removes redundant warnings when composing request options on Web. ## 5.7.0 -- Graceful handling of responses with nonzero `Content-Length`, `Content-Type` json, but empty body - - Empty responses are now transformed to `null` - +- Graceful handling of responses with nonzero `Content-Length`, `Content-Type` that is json, and empty payload. + - Empty responses are now transformed to `null`. ## 5.6.0 diff --git a/dio/lib/src/options.dart b/dio/lib/src/options.dart index c836798b0..1f1e58983 100644 --- a/dio/lib/src/options.dart +++ b/dio/lib/src/options.dart @@ -309,20 +309,6 @@ class Options { ProgressCallback? onReceiveProgress, StackTrace? sourceStackTrace, }) { - if (data != null && kIsWeb) { - if (sendTimeout != null && sendTimeout! > Duration.zero) { - warningLog( - 'sendTimeout cannot be used without a request body to send on Web', - StackTrace.current, - ); - } - if (onSendProgress != null) { - warningLog( - 'onSendProgress cannot be used without a request body to send on Web', - StackTrace.current, - ); - } - } final query = {}; query.addAll(baseOpt.queryParameters); if (queryParameters != null) { diff --git a/plugins/web_adapter/lib/src/adapter.dart b/plugins/web_adapter/lib/src/adapter.dart index cec2d2c47..df43ed629 100644 --- a/plugins/web_adapter/lib/src/adapter.dart +++ b/plugins/web_adapter/lib/src/adapter.dart @@ -55,9 +55,11 @@ class BrowserHttpClientAdapter implements HttpClientAdapter { } }); + final onSendProgress = options.onSendProgress; final sendTimeout = options.sendTimeout ?? Duration.zero; final connectTimeout = options.connectTimeout ?? Duration.zero; final receiveTimeout = options.receiveTimeout ?? Duration.zero; + final xhrTimeout = (connectTimeout + receiveTimeout).inMilliseconds; xhr.timeout = xhrTimeout; @@ -138,7 +140,6 @@ class BrowserHttpClientAdapter implements HttpClientAdapter { }); } - final onSendProgress = options.onSendProgress; if (onSendProgress != null) { xhrUploadProgressStream.listen((event) { onSendProgress(event.loaded, event.total); @@ -147,13 +148,13 @@ class BrowserHttpClientAdapter implements HttpClientAdapter { } else { if (sendTimeout > Duration.zero) { warningLog( - 'sendTimeout cannot be used without a request body to send', + 'sendTimeout cannot be used without a request body to send on Web', StackTrace.current, ); } - if (options.onSendProgress != null) { + if (onSendProgress != null) { warningLog( - 'onSendProgress cannot be used without a request body to send', + 'onSendProgress cannot be used without a request body to send on Web', StackTrace.current, ); }