TF-2311 Set timeout when get session
Signed-off-by: dab246 <tdvu@linagora.com> Signed-off-by: dab246 <tdvu@linagora.com> Signed-off-by: dab246 <tdvu@linagora.com> (cherry picked from commit 3e2c22c65101ee08e0e48ef0e4a737e510b387fb)
This commit is contained in:
@@ -19,7 +19,7 @@ import 'package:tmail_ui_user/features/upload/data/network/file_uploader.dart';
|
||||
class AuthorizationInterceptors extends QueuedInterceptorsWrapper {
|
||||
|
||||
static const int _maxRetryCount = 3;
|
||||
static const String RETRY_KEY = 'Retry';
|
||||
static const String _retryKey = 'Retry';
|
||||
|
||||
final Dio _dio;
|
||||
final AuthenticationClientBase _authenticationClient;
|
||||
@@ -59,7 +59,7 @@ class AuthorizationInterceptors extends QueuedInterceptorsWrapper {
|
||||
|
||||
@override
|
||||
void onRequest(RequestOptions options, RequestInterceptorHandler handler) {
|
||||
log('AuthorizationInterceptors::onRequest():data: ${options.data} | header: ${options.headers}');
|
||||
log('AuthorizationInterceptors::onRequest():url: ${options.uri} | data: ${options.data} | header: ${options.headers}');
|
||||
switch(_authenticationType) {
|
||||
case AuthenticationType.basic:
|
||||
if (_authorization != null) {
|
||||
@@ -83,7 +83,7 @@ class AuthorizationInterceptors extends QueuedInterceptorsWrapper {
|
||||
try {
|
||||
final requestOptions = err.requestOptions;
|
||||
final extraInRequest = requestOptions.extra;
|
||||
var retries = extraInRequest[RETRY_KEY] ?? 0;
|
||||
var retries = extraInRequest[_retryKey] ?? 0;
|
||||
|
||||
if (_validateToRefreshToken(err)) {
|
||||
log('AuthorizationInterceptors::onError:>> _validateToRefreshToken');
|
||||
@@ -145,7 +145,7 @@ class AuthorizationInterceptors extends QueuedInterceptorsWrapper {
|
||||
retries++;
|
||||
|
||||
requestOptions.headers[HttpHeaders.authorizationHeader] = _getTokenAsBearerHeader(_token!.token);
|
||||
requestOptions.extra = {RETRY_KEY: retries};
|
||||
requestOptions.extra = {_retryKey: retries};
|
||||
|
||||
final response = await _dio.fetch(requestOptions);
|
||||
return handler.resolve(response);
|
||||
@@ -218,4 +218,4 @@ class AuthorizationInterceptors extends QueuedInterceptorsWrapper {
|
||||
_configOIDC = null;
|
||||
_authenticationType = AuthenticationType.none;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import 'package:core/utils/app_logger.dart';
|
||||
import 'package:core/utils/platform_info.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:tmail_ui_user/features/login/data/network/endpoint.dart';
|
||||
|
||||
class TimeOutInterceptors extends InterceptorsWrapper {
|
||||
|
||||
static const Duration _sessionConnectTimeout = Duration(milliseconds: 5000);
|
||||
static const Duration _sessionReceiveTimeout = Duration(milliseconds: 5000);
|
||||
|
||||
@override
|
||||
void onRequest(RequestOptions options, RequestInterceptorHandler handler) {
|
||||
log('TimeOutInterceptors::onRequest():url: ${options.uri}');
|
||||
if (PlatformInfo.isMobile && _validateToGetSession(options.uri)) {
|
||||
options.connectTimeout = _sessionConnectTimeout;
|
||||
options.receiveTimeout = _sessionReceiveTimeout;
|
||||
}
|
||||
super.onRequest(options, handler);
|
||||
}
|
||||
|
||||
bool _validateToGetSession(Uri uri) => uri.toString().endsWith(Endpoint.sessionPath.path);
|
||||
}
|
||||
@@ -2,4 +2,5 @@ import 'package:core/data/network/config/service_path.dart';
|
||||
|
||||
class Endpoint {
|
||||
static final ServicePath webFinger = ServicePath('/.well-known/webfinger');
|
||||
static final ServicePath sessionPath = ServicePath('/.well-known/jmap');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user