From 6402694aa822cbb6cc333c8a8a68857db73bda7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Ueko=CC=88tter?= Date: Fri, 14 Jan 2022 21:27:51 +0100 Subject: [PATCH 1/2] Remove send and receive timeout --- dio/lib/src/adapters/browser_adapter.dart | 71 ++--------- dio/lib/src/adapters/io_adapter.dart | 77 +++--------- dio/lib/src/entry/dio_for_native.dart | 16 --- dio/lib/src/interceptors/log.dart | 4 +- dio/lib/src/options.dart | 136 ++++------------------ dio/test/download_test.dart | 14 --- dio/test/options_test.dart | 16 +-- dio/test/readtimeout_test.dart | 25 +--- dio/test/request_test.dart | 3 +- 9 files changed, 57 insertions(+), 305 deletions(-) diff --git a/dio/lib/src/adapters/browser_adapter.dart b/dio/lib/src/adapters/browser_adapter.dart index 6a9027844..ce1f10c13 100644 --- a/dio/lib/src/adapters/browser_adapter.dart +++ b/dio/lib/src/adapters/browser_adapter.dart @@ -45,13 +45,7 @@ class BrowserHttpClientAdapter implements HttpClientAdapter { options.headers.remove(Headers.contentLengthHeader); options.headers.forEach((key, v) => xhr.setRequestHeader(key, '$v')); - final connectTimeout = options.connectTimeout; - final receiveTimeout = options.receiveTimeout; - if (connectTimeout != null && - receiveTimeout != null && - receiveTimeout > Duration.zero) { - xhr.timeout = (connectTimeout + receiveTimeout).inMilliseconds; - } + xhr.timeout = options.connectionTimeout?.inMilliseconds; var completer = Completer(); @@ -70,7 +64,7 @@ class BrowserHttpClientAdapter implements HttpClientAdapter { bool haveSent = false; - final connectionTimeout = options.connectTimeout; + final connectionTimeout = options.connectionTimeout; if (connectionTimeout != null) { Future.delayed(connectionTimeout).then( (value) { @@ -78,7 +72,7 @@ class BrowserHttpClientAdapter implements HttpClientAdapter { completer.completeError( DioError( requestOptions: options, - error: 'Connecting timed out [${options.connectTimeout}ms]', + error: 'Connecting timed out [${options.connectionTimeout}ms]', type: DioErrorType.connectTimeout, ), StackTrace.current, @@ -89,62 +83,19 @@ class BrowserHttpClientAdapter implements HttpClientAdapter { ); } - final uploadStopwatch = Stopwatch(); xhr.upload.onProgress.listen((event) { - haveSent = true; - final sendTimeout = options.sendTimeout; - if (sendTimeout != null) { - if (!uploadStopwatch.isRunning) { - uploadStopwatch.start(); - } - - var duration = uploadStopwatch.elapsed; - if (duration > sendTimeout) { - uploadStopwatch.stop(); - completer.completeError( - DioError( - requestOptions: options, - error: 'Sending timed out [${options.sendTimeout}ms]', - type: DioErrorType.sendTimeout, - ), - StackTrace.current, - ); - xhr.abort(); - } - } - if (options.onSendProgress != null && - event.loaded != null && - event.total != null) { - options.onSendProgress!(event.loaded!, event.total!); + final loaded = event.loaded; + final total = event.total; + if (loaded != null && total != null) { + options.onSendProgress?.call(loaded, total); } }); - final downloadStopwatch = Stopwatch(); xhr.onProgress.listen((event) { - final reveiveTimeout = options.receiveTimeout; - if (reveiveTimeout != null) { - if (!uploadStopwatch.isRunning) { - uploadStopwatch.start(); - } - - final duration = downloadStopwatch.elapsed; - if (duration > reveiveTimeout) { - downloadStopwatch.stop(); - completer.completeError( - DioError( - requestOptions: options, - error: 'Receiving timed out [${options.receiveTimeout}ms]', - type: DioErrorType.receiveTimeout, - ), - StackTrace.current, - ); - xhr.abort(); - } - } - if (options.onReceiveProgress != null) { - if (event.loaded != null && event.total != null) { - options.onReceiveProgress!(event.loaded!, event.total!); - } + final loaded = event.loaded; + final total = event.total; + if (loaded != null && total != null) { + options.onReceiveProgress?.call(loaded, total); } }); diff --git a/dio/lib/src/adapters/io_adapter.dart b/dio/lib/src/adapters/io_adapter.dart index e3a903403..98a143bc6 100644 --- a/dio/lib/src/adapters/io_adapter.dart +++ b/dio/lib/src/adapters/io_adapter.dart @@ -22,6 +22,14 @@ class DefaultHttpClientAdapter implements HttpClientAdapter { bool _closed = false; + void _throwConnectingTimeout(RequestOptions options) { + throw DioError( + requestOptions: options, + error: 'Connecting timed out [${options.connectionTimeout}]', + type: DioErrorType.connectTimeout, + ); + } + @override Future fetch( RequestOptions options, @@ -30,22 +38,16 @@ class DefaultHttpClientAdapter implements HttpClientAdapter { ) async { if (_closed) { throw Exception( - "Can't establish connection after [HttpClientAdapter] closed!"); - } - var _httpClient = _configHttpClient(cancelFuture, options.connectTimeout); - var reqFuture = _httpClient.openUrl(options.method, options.uri); - - void _throwConnectingTimeout() { - throw DioError( - requestOptions: options, - error: 'Connecting timed out [${options.connectTimeout}ms]', - type: DioErrorType.connectTimeout, + "Can't establish connection after [HttpClientAdapter] closed!", ); } + var _httpClient = + _configHttpClient(cancelFuture, options.connectionTimeout); + var reqFuture = _httpClient.openUrl(options.method, options.uri); late HttpClientRequest request; try { - final connectionTimeout = options.connectTimeout; + final connectionTimeout = options.connectionTimeout; if (connectionTimeout != null) { request = await reqFuture.timeout(connectionTimeout); } else { @@ -58,11 +60,11 @@ class DefaultHttpClientAdapter implements HttpClientAdapter { }); } on SocketException catch (e) { if (e.message.contains('timed out')) { - _throwConnectingTimeout(); + _throwConnectingTimeout(options); } rethrow; } on TimeoutException { - _throwConnectingTimeout(); + _throwConnectingTimeout(options); } request.followRedirects = options.followRedirects; @@ -70,58 +72,15 @@ class DefaultHttpClientAdapter implements HttpClientAdapter { if (requestStream != null) { // Transform the request data - var future = request.addStream(requestStream); - final sendTimeout = options.sendTimeout; - if (sendTimeout != null) { - future = future.timeout(sendTimeout); - } - try { - await future; - } on TimeoutException { - throw DioError( - requestOptions: options, - error: 'Sending timeout[${options.sendTimeout}ms]', - type: DioErrorType.sendTimeout, - ); - } + await request.addStream(requestStream); } - final stopwatch = Stopwatch()..start(); - var future = request.close(); - final receiveTimeout = options.receiveTimeout; - if (receiveTimeout != null) { - future = future.timeout(receiveTimeout); - } - late HttpClientResponse responseStream; - try { - responseStream = await future; - } on TimeoutException { - throw DioError( - requestOptions: options, - error: 'Receiving data timeout[${options.receiveTimeout}]', - type: DioErrorType.receiveTimeout, - ); - } + HttpClientResponse responseStream = await request.close(); var stream = responseStream.transform(StreamTransformer.fromHandlers( handleData: (data, sink) { - stopwatch.stop(); - final duration = stopwatch.elapsed; - final receiveTimeout = options.receiveTimeout; - if (receiveTimeout != null && duration > receiveTimeout) { - sink.addError( - DioError( - requestOptions: options, - error: 'Receiving data timeout[${options.receiveTimeout}]', - type: DioErrorType.receiveTimeout, - ), - ); - //todo: to verify - responseStream.detachSocket().then((socket) => socket.close()); - } else { - sink.add(Uint8List.fromList(data)); - } + sink.add(Uint8List.fromList(data)); }, )); diff --git a/dio/lib/src/entry/dio_for_native.dart b/dio/lib/src/entry/dio_for_native.dart index e6f6b0f81..225ca155e 100644 --- a/dio/lib/src/entry/dio_for_native.dart +++ b/dio/lib/src/entry/dio_for_native.dart @@ -216,22 +216,6 @@ class DioForNative with DioMixin implements Dio { await _closeAndDelete(); }); - final timeout = response.requestOptions.receiveTimeout; - if (timeout != null) { - future = future.timeout(timeout).catchError((Object err) async { - await subscription.cancel(); - await _closeAndDelete(); - if (err is TimeoutException) { - throw DioError( - requestOptions: response.requestOptions, - error: 'Receiving data timeout[$timeout]', - type: DioErrorType.receiveTimeout, - ); - } else { - throw err; - } - }); - } return DioMixin.listenCancelForAsyncTask(cancelToken, future); } diff --git a/dio/lib/src/interceptors/log.dart b/dio/lib/src/interceptors/log.dart index 3ad3bc244..57a1e7854 100644 --- a/dio/lib/src/interceptors/log.dart +++ b/dio/lib/src/interceptors/log.dart @@ -59,9 +59,7 @@ class LogInterceptor extends Interceptor { _printKV('method', options.method); _printKV('responseType', options.responseType.toString()); _printKV('followRedirects', options.followRedirects); - _printKV('connectTimeout', options.connectTimeout); - _printKV('sendTimeout', options.sendTimeout); - _printKV('receiveTimeout', options.receiveTimeout); + _printKV('connectTimeout', options.connectionTimeout); _printKV( 'receiveDataWhenStatusError', options.receiveDataWhenStatusError); _printKV('extra', options.extra); diff --git a/dio/lib/src/options.dart b/dio/lib/src/options.dart index 8c5e33f6e..ebcdead6f 100644 --- a/dio/lib/src/options.dart +++ b/dio/lib/src/options.dart @@ -82,9 +82,7 @@ typedef RequestEncoder = List Function( class BaseOptions extends _RequestConfig with OptionsMixin { BaseOptions({ String? method, - Duration? connectTimeout, - Duration? receiveTimeout, - Duration? sendTimeout, + Duration? connectionTimeout, String baseUrl = '', Map? queryParameters, Map? extra, @@ -99,11 +97,9 @@ class BaseOptions extends _RequestConfig with OptionsMixin { ResponseDecoder? responseDecoder, ListFormat? listFormat, this.setRequestContentTypeWhenNoPayload = false, - }) : assert(connectTimeout == null || !connectTimeout.isNegative), + }) : assert(connectionTimeout == null || !connectionTimeout.isNegative), super( method: method, - receiveTimeout: receiveTimeout, - sendTimeout: sendTimeout, extra: extra, headers: headers, responseType: responseType, @@ -118,7 +114,7 @@ class BaseOptions extends _RequestConfig with OptionsMixin { ) { this.queryParameters = queryParameters ?? {}; this.baseUrl = baseUrl; - this.connectTimeout = connectTimeout; + this.connectionTimeout = connectionTimeout; } /// Create a Option from current instance with merging attributes. @@ -127,7 +123,7 @@ class BaseOptions extends _RequestConfig with OptionsMixin { String? baseUrl, Map? queryParameters, String? path, - Duration? connectTimeout, + Duration? connectionTimeout, Duration? receiveTimeout, Duration? sendTimeout, Map? extra, @@ -147,9 +143,7 @@ class BaseOptions extends _RequestConfig with OptionsMixin { method: method ?? this.method, baseUrl: baseUrl ?? this.baseUrl, queryParameters: queryParameters ?? this.queryParameters, - connectTimeout: connectTimeout ?? this.connectTimeout, - receiveTimeout: receiveTimeout ?? this.receiveTimeout, - sendTimeout: sendTimeout ?? this.sendTimeout, + connectionTimeout: connectionTimeout ?? this.connectionTimeout, extra: extra ?? Map.from(this.extra), headers: headers ?? Map.from(this.headers), responseType: responseType ?? this.responseType, @@ -194,26 +188,24 @@ mixin OptionsMixin { late Map queryParameters; /// Timeout in milliseconds for opening url. - /// [Dio] will throw the [DioError] with [DioErrorType.connectTimeout] type + /// [Dio] will throw the [DioError] with [DioErrorType.connectionTimeout] type /// when time out. - Duration? get connectTimeout => _connectTimeout; + Duration? get connectionTimeout => _connectionTimeout; - set connectTimeout(Duration? value) { + set connectionTimeout(Duration? value) { if (value != null && value.isNegative) { - throw StateError("connectTimeout should be positive"); + throw StateError("connectionTimeout should be positive"); } - _connectTimeout = value; + _connectionTimeout = value; } - Duration? _connectTimeout; + Duration? _connectionTimeout; } /// Every request can pass an [Options] object which will be merged with [Dio.options] class Options { Options({ this.method, - Duration? sendTimeout, - Duration? receiveTimeout, this.extra, this.headers, this.responseType, @@ -225,16 +217,11 @@ class Options { this.requestEncoder, this.responseDecoder, this.listFormat, - }) : assert(receiveTimeout == null || !receiveTimeout.isNegative), - _receiveTimeout = receiveTimeout, - assert(sendTimeout == null || !sendTimeout.isNegative), - _sendTimeout = sendTimeout; + }); /// Create a Option from current instance with merging attributes. Options copyWith({ String? method, - Duration? sendTimeout, - Duration? receiveTimeout, Map? extra, Map? headers, ResponseType? responseType, @@ -268,8 +255,6 @@ class Options { return Options( method: method ?? this.method, - sendTimeout: sendTimeout ?? this.sendTimeout, - receiveTimeout: receiveTimeout ?? this.receiveTimeout, extra: extra ?? _extra, headers: headers ?? _headers, responseType: responseType ?? this.responseType, @@ -321,9 +306,7 @@ class Options { baseUrl: baseOpt.baseUrl, path: path, data: data, - connectTimeout: baseOpt.connectTimeout, - sendTimeout: sendTimeout ?? baseOpt.sendTimeout, - receiveTimeout: receiveTimeout ?? baseOpt.receiveTimeout, + connectionTimeout: baseOpt.connectionTimeout, responseType: responseType ?? baseOpt.responseType, validateStatus: validateStatus ?? baseOpt.validateStatus, receiveDataWhenStatusError: @@ -356,37 +339,6 @@ class Options { /// regard as the same key. Map? headers; - /// Timeout in milliseconds for sending data. - /// [Dio] will throw the [DioError] with [DioErrorType.sendTimeout] type - /// when time out. - Duration? get sendTimeout => _sendTimeout; - - set sendTimeout(Duration? value) { - if (value != null && value.isNegative) { - throw StateError("sendTimeout should be positive"); - } - _sendTimeout = value; - } - - Duration? _sendTimeout; - - /// Timeout in milliseconds for receiving data. - /// - /// Note: [receiveTimeout] represents a timeout during data transfer! That is to say the - /// client has connected to the server, and the server starts to send data to the client. - /// - /// `null` meanings no timeout limit. - Duration? get receiveTimeout => _receiveTimeout; - - set receiveTimeout(Duration? value) { - if (value != null && value.isNegative) { - throw StateError('receiveTimeout should be positive'); - } - _receiveTimeout = value; - } - - Duration? _receiveTimeout; - /// The request Content-Type. The default value is [ContentType.json]. /// If you want to encode request body with 'application/x-www-form-urlencoded', /// you can set `ContentType.parse('application/x-www-form-urlencoded')`, and [Dio] @@ -449,9 +401,7 @@ class Options { class RequestOptions extends _RequestConfig with OptionsMixin { RequestOptions({ String? method, - Duration? sendTimeout, - Duration? receiveTimeout, - Duration? connectTimeout, + Duration? connectionTimeout, this.data, required this.path, Map? queryParameters, @@ -471,11 +421,9 @@ class RequestOptions extends _RequestConfig with OptionsMixin { ResponseDecoder? responseDecoder, ListFormat? listFormat, bool? setRequestContentTypeWhenNoPayload, - }) : assert(connectTimeout == null || !connectTimeout.isNegative), + }) : assert(connectionTimeout == null || !connectionTimeout.isNegative), super( method: method, - sendTimeout: sendTimeout, - receiveTimeout: receiveTimeout, extra: extra, headers: headers, responseType: responseType, @@ -490,15 +438,13 @@ class RequestOptions extends _RequestConfig with OptionsMixin { ) { this.queryParameters = queryParameters ?? {}; this.baseUrl = baseUrl ?? ''; - this.connectTimeout = connectTimeout; + this.connectionTimeout = connectionTimeout; } /// Create a Option from current instance with merging attributes. RequestOptions copyWith({ String? method, - Duration? sendTimeout, - Duration? receiveTimeout, - Duration? connectTimeout, + Duration? connectionTimeout, String? data, String? path, Map? queryParameters, @@ -528,12 +474,14 @@ class RequestOptions extends _RequestConfig with OptionsMixin { !(contentType != null && contentTypeInHeader), 'You cannot set both contentType param and a content-type header', ); + assert( + connectionTimeout == null || connectionTimeout.isNegative, + 'connectionTimeout must be positive', + ); var ro = RequestOptions( method: method ?? this.method, - sendTimeout: sendTimeout ?? this.sendTimeout, - receiveTimeout: receiveTimeout ?? this.receiveTimeout, - connectTimeout: connectTimeout ?? this.connectTimeout, + connectionTimeout: connectionTimeout ?? this.connectionTimeout, data: data ?? this.data, path: path ?? this.path, baseUrl: baseUrl ?? this.baseUrl, @@ -605,8 +553,6 @@ class RequestOptions extends _RequestConfig with OptionsMixin { /// The [_RequestConfig] class describes the http request information and configuration. class _RequestConfig { _RequestConfig({ - Duration? receiveTimeout, - Duration? sendTimeout, String? method, Map? extra, Map? headers, @@ -619,10 +565,7 @@ class _RequestConfig { ResponseType? responseType, this.requestEncoder, this.responseDecoder, - }) : assert(receiveTimeout == null || !receiveTimeout.isNegative), - _receiveTimeout = receiveTimeout, - assert(sendTimeout == null || !sendTimeout.isNegative), - _sendTimeout = sendTimeout { + }) { this.headers = headers; var contentTypeInHeader = @@ -669,39 +612,6 @@ class _RequestConfig { } } - /// Timeout in milliseconds for sending data. - /// [Dio] will throw the [DioError] with [DioErrorType.sendTimeout] type - /// when time out. - /// - /// `null` meanings no timeout limit. - Duration? get sendTimeout => _sendTimeout; - - set sendTimeout(Duration? value) { - if (value != null && value.isNegative) { - throw StateError("sendTimeout should be positive"); - } - _sendTimeout = value; - } - - Duration? _sendTimeout; - - /// Timeout in milliseconds for receiving data. - /// - /// Note: [receiveTimeout] represents a timeout during data transfer! That is to say the - /// client has connected to the server, and the server starts to send data to the client. - /// - /// `null` meanings no timeout limit. - Duration? get receiveTimeout => _receiveTimeout; - - set receiveTimeout(Duration? value) { - if (value != null && value.isNegative) { - throw StateError("reveiveTimeout should be positive"); - } - _receiveTimeout = value; - } - - Duration? _receiveTimeout; - /// The request Content-Type. The default value is [ContentType.json]. /// If you want to encode request body with 'application/x-www-form-urlencoded', /// you can set `ContentType.parse('application/x-www-form-urlencoded')`, and [Dio] diff --git a/dio/test/download_test.dart b/dio/test/download_test.dart index 0b6e8cd59..9387b4738 100644 --- a/dio/test/download_test.dart +++ b/dio/test/download_test.dart @@ -61,20 +61,6 @@ void main() { assert(r.data == null); }); - test('#test download timeout', () async { - const savePath = 'test/_download_test.md'; - var dio = Dio(BaseOptions( - receiveTimeout: Duration(milliseconds: 1), - baseUrl: serverUrl.toString(), - )); - expect( - dio - .download('/download', savePath) - .catchError((e) => throw (e as DioError).type), - throwsA(DioErrorType.receiveTimeout)); - //print(r); - }); - test('#test download cancellation', () async { const savePath = 'test/_download_test.md'; var cancelToken = CancelToken(); diff --git a/dio/test/options_test.dart b/dio/test/options_test.dart index fc00ff110..271f64d60 100644 --- a/dio/test/options_test.dart +++ b/dio/test/options_test.dart @@ -12,9 +12,7 @@ void main() { var map = {'a': '5'}; var mapOverride = {'b': '6'}; var baseOptions = BaseOptions( - connectTimeout: Duration(seconds: 2), - receiveTimeout: Duration(seconds: 2), - sendTimeout: Duration(seconds: 2), + connectionTimeout: Duration(seconds: 2), baseUrl: 'http://localhost', queryParameters: map, extra: map, @@ -32,8 +30,7 @@ void main() { contentType: 'text/html', ); assert(opt1.method == 'post'); - assert(opt1.receiveTimeout == Duration(seconds: 3)); - assert(opt1.connectTimeout == Duration(seconds: 2)); + assert(opt1.connectionTimeout == Duration(seconds: 2)); assert(opt1.followRedirects == false); assert(opt1.baseUrl == 'https://flutterchina.club'); assert(opt1.headers['b'] == '6'); @@ -43,8 +40,6 @@ void main() { var opt2 = Options( method: 'get', - receiveTimeout: Duration(seconds: 2), - sendTimeout: Duration(seconds: 2), extra: map, headers: map, contentType: 'application/json', @@ -53,15 +48,12 @@ void main() { var opt3 = opt2.copyWith( method: 'post', - receiveTimeout: Duration(seconds: 3), - sendTimeout: Duration(seconds: 3), extra: mapOverride, headers: mapOverride, contentType: 'text/html', ); assert(opt3.method == 'post'); - assert(opt3.receiveTimeout == Duration(seconds: 3)); assert(opt3.followRedirects == false); assert(opt3.headers!['b'] == '6'); assert(opt3.extra!['b'] == '6'); @@ -69,13 +61,10 @@ void main() { var opt4 = RequestOptions( path: '/xxx', - sendTimeout: Duration(seconds: 2), followRedirects: false, ); var opt5 = opt4.copyWith( method: 'post', - receiveTimeout: Duration(seconds: 3), - sendTimeout: Duration(seconds: 3), extra: mapOverride, headers: mapOverride, data: 'xx=5', @@ -83,7 +72,6 @@ void main() { contentType: 'text/html', ); assert(opt5.method == 'post'); - assert(opt5.receiveTimeout == Duration(seconds: 3)); assert(opt5.followRedirects == false); assert(opt5.contentType == 'text/html'); assert(opt5.headers['b'] == '6'); diff --git a/dio/test/readtimeout_test.dart b/dio/test/readtimeout_test.dart index 26876329b..d9067cbb0 100644 --- a/dio/test/readtimeout_test.dart +++ b/dio/test/readtimeout_test.dart @@ -52,29 +52,6 @@ void main() { tearDown(stopServer); - test( - '#read_timeout - catch DioError when receiveTimeout < $_sleepDurationAfterConnectionEstablished', - () async { - var dio = Dio(); - - dio.options - ..baseUrl = serverUrl.toString() - ..receiveTimeout = - _sleepDurationAfterConnectionEstablished - Duration(seconds: 1); - - DioError error; - - try { - await dio.get('/'); - fail('did not throw'); - } on DioError catch (e) { - error = e; - } - - expect(error, isNotNull); - expect(error.type == DioErrorType.receiveTimeout, isTrue); - }); - test( '#read_timeout - no DioError when receiveTimeout > $_sleepDurationAfterConnectionEstablished', () async { @@ -82,7 +59,7 @@ void main() { dio.options ..baseUrl = serverUrl.toString() - ..connectTimeout = + ..connectionTimeout = _sleepDurationAfterConnectionEstablished + Duration(seconds: 1); DioError? error; diff --git a/dio/test/request_test.dart b/dio/test/request_test.dart index 00e406baa..6456f4471 100644 --- a/dio/test/request_test.dart +++ b/dio/test/request_test.dart @@ -19,8 +19,7 @@ void main() { dio = Dio(); dio.options ..baseUrl = serverUrl.toString() - ..connectTimeout = Duration(seconds: 1) - ..receiveTimeout = Duration(seconds: 5) + ..connectionTimeout = Duration(seconds: 1) ..headers = {'User-Agent': 'dartisan'}; dio.interceptors.add(LogInterceptor( responseBody: true, From 12022e20252ecd67a67ff24623f0671b3e6cf8da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Ueko=CC=88tter?= Date: Fri, 14 Jan 2022 21:30:38 +0100 Subject: [PATCH 2/2] fix examples --- example/lib/dio.dart | 2 -- example/lib/download.dart | 1 - example/lib/options.dart | 2 -- example/lib/post_stream_and_bytes.dart | 1 - example/lib/request_interceptors.dart | 1 - example_flutter_app/lib/routes/request.dart | 4 +--- plugins/http2_adapter/lib/src/connection_manager_imp.dart | 4 ++-- 7 files changed, 3 insertions(+), 12 deletions(-) diff --git a/example/lib/dio.dart b/example/lib/dio.dart index dfa3aa507..d26926dd9 100644 --- a/example/lib/dio.dart +++ b/example/lib/dio.dart @@ -5,8 +5,6 @@ void main() async { var dio = Dio(); dio.options ..baseUrl = 'http://httpbin.org/' - ..connectTimeout = Duration(seconds: 5) - ..receiveTimeout = Duration(seconds: 5) ..validateStatus = (int? status) { return status != null && status > 0; } diff --git a/example/lib/download.dart b/example/lib/download.dart index ae51f2740..9ea981b50 100644 --- a/example/lib/download.dart +++ b/example/lib/download.dart @@ -42,7 +42,6 @@ Future download2(Dio dio, String url, String savePath) async { options: Options( responseType: ResponseType.bytes, followRedirects: false, - receiveTimeout: Duration.zero, ), ); print(response.headers); diff --git a/example/lib/options.dart b/example/lib/options.dart index 430c4a066..0eef3c4b0 100644 --- a/example/lib/options.dart +++ b/example/lib/options.dart @@ -4,8 +4,6 @@ import 'package:dio/dio.dart'; void main() async { var dio = Dio(BaseOptions( baseUrl: 'http://httpbin.org/', - connectTimeout: Duration(seconds: 5), - receiveTimeout: Duration(seconds: 10), // 5s headers: { HttpHeaders.userAgentHeader: 'dio', diff --git a/example/lib/post_stream_and_bytes.dart b/example/lib/post_stream_and_bytes.dart index dc9055468..8d11bfb63 100644 --- a/example/lib/post_stream_and_bytes.dart +++ b/example/lib/post_stream_and_bytes.dart @@ -6,7 +6,6 @@ import 'package:dio/dio.dart'; void main() async { var dio = Dio(BaseOptions( - connectTimeout: Duration(seconds: 5), baseUrl: 'http://httpbin.org/', )); diff --git a/example/lib/request_interceptors.dart b/example/lib/request_interceptors.dart index ade036a25..fb45fd2dd 100644 --- a/example/lib/request_interceptors.dart +++ b/example/lib/request_interceptors.dart @@ -3,7 +3,6 @@ import 'package:dio/dio.dart'; void main() async { var dio = Dio(); dio.options.baseUrl = 'http://httpbin.org/'; - dio.options.connectTimeout = Duration(seconds: 5); dio.interceptors.add(InterceptorsWrapper(onRequest: (options, handler) { switch (options.path) { case '/fakepath1': diff --git a/example_flutter_app/lib/routes/request.dart b/example_flutter_app/lib/routes/request.dart index 5f685a66b..6b6efc25c 100644 --- a/example_flutter_app/lib/routes/request.dart +++ b/example_flutter_app/lib/routes/request.dart @@ -40,9 +40,7 @@ class _RequestRouteState extends State { .post( "http://httpbin.org/post", data: formData, - options: Options( - sendTimeout: Duration(seconds: 2), - receiveTimeout: Duration(seconds: 0)), + options: Options(), onSendProgress: (a, b) => print('send ${a / b}'), onReceiveProgress: (a, b) => print('received ${a / b}'), ) diff --git a/plugins/http2_adapter/lib/src/connection_manager_imp.dart b/plugins/http2_adapter/lib/src/connection_manager_imp.dart index 7175b06fe..ff266eb0f 100644 --- a/plugins/http2_adapter/lib/src/connection_manager_imp.dart +++ b/plugins/http2_adapter/lib/src/connection_manager_imp.dart @@ -71,7 +71,7 @@ class _ConnectionManager implements ConnectionManager { socket = await SecureSocket.connect( uri.host, uri.port, - timeout: options.connectTimeout, + timeout: options.connectionTimeout, context: clientConfig.context, onBadCertificate: clientConfig.onBadCertificate, supportedProtocols: ['h2'], @@ -81,7 +81,7 @@ class _ConnectionManager implements ConnectionManager { if (e.message.contains('timed out')) { throw DioError( requestOptions: options, - error: 'Connecting timed out [${options.connectTimeout}]', + error: 'Connecting timed out [${options.connectionTimeout}]', type: DioErrorType.connectTimeout, ); }