dio
dio copied to clipboard
fix connection timeout runtime
New Pull Request Checklist
- [x] I have read the Documentation
- [x] I have searched for a similar pull request in the project and found none
- [x] I have updated this branch with the latest
develop
to avoid conflicts (via merge from master or rebase) - [x] I have added the required tests to prove the fix/feature I am adding
- [x] I have updated the documentation (if necessary)
- [x] I have run the tests and they pass
This merge request fixes / refers to the following issues: ...
Pull Request Description
Bug : when changing the connection timeout in run time ,its being ignore this cus by this lines : loot at the comment
HttpClient _configHttpClient(Future? cancelFuture, int connectionTimeout) {
var _connectionTimeout = connectionTimeout > 0
? Duration(milliseconds: connectionTimeout)
: null;
if (cancelFuture != null) {
var _httpClient = HttpClient();
_httpClient.userAgent = null;
if (onHttpClientCreate != null) {
//user can return a HttpClient instance
_httpClient = onHttpClientCreate!(_httpClient) ?? _httpClient;
}
_httpClient.idleTimeout = Duration(seconds: 0);
cancelFuture.whenComplete(() {
Future.delayed(Duration(seconds: 0)).then((e) {
try {
_httpClient.close(force: true);
} catch (e) {
//...
}
});
});
return _httpClient..connectionTimeout = _connectionTimeout;
}
if (_defaultHttpClient == null) {
_defaultHttpClient = HttpClient();
_defaultHttpClient!.idleTimeout = Duration(seconds: 3);
if (onHttpClientCreate != null) {
//user can return a HttpClient instance
_defaultHttpClient =
onHttpClientCreate!(_defaultHttpClient!) ?? _defaultHttpClient;
}
_defaultHttpClient!.connectionTimeout = _connectionTimeout; // --> this line never calls when changing timeout connection
}
return _defaultHttpClient!;
}
so i remove this line and set the new connection timeout in the return
good catch, and hope it will be merged soon!
Beautiful solution which also includes unit test! Can you please expedite this one?
been waiting for this one - nicely done!!
When plan to release this fix?
I'm using my own fork because of this issue and lack of PR being released. Disappointing :-(