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 {
|
class AuthorizationInterceptors extends QueuedInterceptorsWrapper {
|
||||||
|
|
||||||
static const int _maxRetryCount = 3;
|
static const int _maxRetryCount = 3;
|
||||||
static const String RETRY_KEY = 'Retry';
|
static const String _retryKey = 'Retry';
|
||||||
|
|
||||||
final Dio _dio;
|
final Dio _dio;
|
||||||
final AuthenticationClientBase _authenticationClient;
|
final AuthenticationClientBase _authenticationClient;
|
||||||
@@ -59,7 +59,7 @@ class AuthorizationInterceptors extends QueuedInterceptorsWrapper {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
void onRequest(RequestOptions options, RequestInterceptorHandler handler) {
|
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) {
|
switch(_authenticationType) {
|
||||||
case AuthenticationType.basic:
|
case AuthenticationType.basic:
|
||||||
if (_authorization != null) {
|
if (_authorization != null) {
|
||||||
@@ -83,7 +83,7 @@ class AuthorizationInterceptors extends QueuedInterceptorsWrapper {
|
|||||||
try {
|
try {
|
||||||
final requestOptions = err.requestOptions;
|
final requestOptions = err.requestOptions;
|
||||||
final extraInRequest = requestOptions.extra;
|
final extraInRequest = requestOptions.extra;
|
||||||
var retries = extraInRequest[RETRY_KEY] ?? 0;
|
var retries = extraInRequest[_retryKey] ?? 0;
|
||||||
|
|
||||||
if (_validateToRefreshToken(err)) {
|
if (_validateToRefreshToken(err)) {
|
||||||
log('AuthorizationInterceptors::onError:>> _validateToRefreshToken');
|
log('AuthorizationInterceptors::onError:>> _validateToRefreshToken');
|
||||||
@@ -145,7 +145,7 @@ class AuthorizationInterceptors extends QueuedInterceptorsWrapper {
|
|||||||
retries++;
|
retries++;
|
||||||
|
|
||||||
requestOptions.headers[HttpHeaders.authorizationHeader] = _getTokenAsBearerHeader(_token!.token);
|
requestOptions.headers[HttpHeaders.authorizationHeader] = _getTokenAsBearerHeader(_token!.token);
|
||||||
requestOptions.extra = {RETRY_KEY: retries};
|
requestOptions.extra = {_retryKey: retries};
|
||||||
|
|
||||||
final response = await _dio.fetch(requestOptions);
|
final response = await _dio.fetch(requestOptions);
|
||||||
return handler.resolve(response);
|
return handler.resolve(response);
|
||||||
@@ -218,4 +218,4 @@ class AuthorizationInterceptors extends QueuedInterceptorsWrapper {
|
|||||||
_configOIDC = null;
|
_configOIDC = null;
|
||||||
_authenticationType = AuthenticationType.none;
|
_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 {
|
class Endpoint {
|
||||||
static final ServicePath webFinger = ServicePath('/.well-known/webfinger');
|
static final ServicePath webFinger = ServicePath('/.well-known/webfinger');
|
||||||
|
static final ServicePath sessionPath = ServicePath('/.well-known/jmap');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import 'package:tmail_ui_user/features/login/data/local/account_cache_manager.da
|
|||||||
import 'package:tmail_ui_user/features/login/data/local/token_oidc_cache_manager.dart';
|
import 'package:tmail_ui_user/features/login/data/local/token_oidc_cache_manager.dart';
|
||||||
import 'package:tmail_ui_user/features/login/data/network/authentication_client/authentication_client_base.dart';
|
import 'package:tmail_ui_user/features/login/data/network/authentication_client/authentication_client_base.dart';
|
||||||
import 'package:tmail_ui_user/features/login/data/network/config/authorization_interceptors.dart';
|
import 'package:tmail_ui_user/features/login/data/network/config/authorization_interceptors.dart';
|
||||||
|
import 'package:tmail_ui_user/features/login/data/network/config/time_out_interceptors.dart';
|
||||||
import 'package:tmail_ui_user/features/login/data/network/oidc_http_client.dart';
|
import 'package:tmail_ui_user/features/login/data/network/oidc_http_client.dart';
|
||||||
import 'package:tmail_ui_user/features/login/data/utils/library_platform/app_auth_plugin/app_auth_plugin.dart';
|
import 'package:tmail_ui_user/features/login/data/utils/library_platform/app_auth_plugin/app_auth_plugin.dart';
|
||||||
import 'package:tmail_ui_user/features/mailbox/data/network/mailbox_api.dart';
|
import 'package:tmail_ui_user/features/mailbox/data/network/mailbox_api.dart';
|
||||||
@@ -71,12 +72,14 @@ class NetworkBindings extends Bindings {
|
|||||||
Get.find<AccountCacheManager>(),
|
Get.find<AccountCacheManager>(),
|
||||||
));
|
));
|
||||||
Get.put(LocaleInterceptor());
|
Get.put(LocaleInterceptor());
|
||||||
|
Get.put(TimeOutInterceptors());
|
||||||
Get.find<Dio>().interceptors.add(Get.find<DynamicUrlInterceptors>());
|
Get.find<Dio>().interceptors.add(Get.find<DynamicUrlInterceptors>());
|
||||||
Get.find<Dio>().interceptors.add(Get.find<AuthorizationInterceptors>());
|
Get.find<Dio>().interceptors.add(Get.find<AuthorizationInterceptors>());
|
||||||
if (kDebugMode) {
|
if (kDebugMode) {
|
||||||
Get.find<Dio>().interceptors.add(LogInterceptor(requestBody: true));
|
Get.find<Dio>().interceptors.add(LogInterceptor(requestBody: true));
|
||||||
}
|
}
|
||||||
Get.find<Dio>().interceptors.add(Get.find<LocaleInterceptor>());
|
Get.find<Dio>().interceptors.add(Get.find<LocaleInterceptor>());
|
||||||
|
Get.find<Dio>().interceptors.add(Get.find<TimeOutInterceptors>());
|
||||||
}
|
}
|
||||||
|
|
||||||
void _bindingApi() {
|
void _bindingApi() {
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import 'package:tmail_ui_user/features/login/data/local/account_cache_manager.da
|
|||||||
import 'package:tmail_ui_user/features/login/data/local/token_oidc_cache_manager.dart';
|
import 'package:tmail_ui_user/features/login/data/local/token_oidc_cache_manager.dart';
|
||||||
import 'package:tmail_ui_user/features/login/data/network/authentication_client/authentication_client_base.dart';
|
import 'package:tmail_ui_user/features/login/data/network/authentication_client/authentication_client_base.dart';
|
||||||
import 'package:tmail_ui_user/features/login/data/network/config/authorization_interceptors.dart';
|
import 'package:tmail_ui_user/features/login/data/network/config/authorization_interceptors.dart';
|
||||||
|
import 'package:tmail_ui_user/features/login/data/network/config/time_out_interceptors.dart';
|
||||||
import 'package:tmail_ui_user/features/login/data/utils/library_platform/app_auth_plugin/app_auth_plugin.dart';
|
import 'package:tmail_ui_user/features/login/data/utils/library_platform/app_auth_plugin/app_auth_plugin.dart';
|
||||||
import 'package:tmail_ui_user/features/mailbox/data/network/mailbox_isolate_worker.dart';
|
import 'package:tmail_ui_user/features/mailbox/data/network/mailbox_isolate_worker.dart';
|
||||||
import 'package:tmail_ui_user/features/thread/data/network/thread_api.dart';
|
import 'package:tmail_ui_user/features/thread/data/network/thread_api.dart';
|
||||||
@@ -49,6 +50,7 @@ class NetworkIsolateBindings extends Bindings {
|
|||||||
dio.interceptors.add(LogInterceptor(requestBody: true));
|
dio.interceptors.add(LogInterceptor(requestBody: true));
|
||||||
}
|
}
|
||||||
dio.interceptors.add(Get.find<LocaleInterceptor>());
|
dio.interceptors.add(Get.find<LocaleInterceptor>());
|
||||||
|
dio.interceptors.add(Get.find<TimeOutInterceptors>());
|
||||||
}
|
}
|
||||||
|
|
||||||
void _bindingApi() {
|
void _bindingApi() {
|
||||||
|
|||||||
Reference in New Issue
Block a user