diff --git a/src/Android/Android.csproj b/src/Android/Android.csproj index 8bfeb3b11..82c3d63fb 100644 --- a/src/Android/Android.csproj +++ b/src/Android/Android.csproj @@ -71,6 +71,7 @@ + diff --git a/src/Android/MainApplication.cs b/src/Android/MainApplication.cs index fd83053e2..60a4986ab 100644 --- a/src/Android/MainApplication.cs +++ b/src/Android/MainApplication.cs @@ -15,6 +15,7 @@ using Bit.Droid.Services; using Bit.Droid.Utilities; using Plugin.CurrentActivity; using Plugin.Fingerprint; +using Xamarin.Android.Net; #if !FDROID using Android.Gms.Security; #endif @@ -39,7 +40,7 @@ namespace Bit.Droid if(ServiceContainer.RegisteredServices.Count == 0) { RegisterLocalServices(); - ServiceContainer.Init(); + ServiceContainer.Init(new AndroidClientHandler()); if(App.Migration.MigrationHelpers.NeedsMigration()) { var task = App.Migration.MigrationHelpers.PerformMigrationAsync(); diff --git a/src/Core/Services/ApiService.cs b/src/Core/Services/ApiService.cs index e7e8448e4..7583ab664 100644 --- a/src/Core/Services/ApiService.cs +++ b/src/Core/Services/ApiService.cs @@ -22,7 +22,7 @@ namespace Bit.Core.Services { ContractResolver = new CamelCasePropertyNamesContractResolver() }; - private readonly HttpClient _httpClient = new HttpClient(); + private readonly HttpClient _httpClient; private readonly ITokenService _tokenService; private readonly IPlatformUtilsService _platformUtilsService; private readonly Func _logoutCallbackAsync; @@ -31,13 +31,22 @@ namespace Bit.Core.Services public ApiService( ITokenService tokenService, IPlatformUtilsService platformUtilsService, - Func logoutCallbackAsync) + Func logoutCallbackAsync, + HttpMessageHandler httpMessageHandler = null) { _tokenService = tokenService; _platformUtilsService = platformUtilsService; _logoutCallbackAsync = logoutCallbackAsync; var device = _platformUtilsService.GetDevice(); _deviceType = device.ToString(); + if(httpMessageHandler != null) + { + _httpClient = new HttpClient(httpMessageHandler); + } + else + { + _httpClient = new HttpClient(); + } } public bool UrlsSet { get; private set; } diff --git a/src/Core/Utilities/ServiceContainer.cs b/src/Core/Utilities/ServiceContainer.cs index 0b5669d1d..29359602e 100644 --- a/src/Core/Utilities/ServiceContainer.cs +++ b/src/Core/Utilities/ServiceContainer.cs @@ -2,6 +2,7 @@ using Bit.Core.Services; using System; using System.Collections.Generic; +using System.Net.Http; using System.Threading.Tasks; namespace Bit.Core.Utilities @@ -11,7 +12,7 @@ namespace Bit.Core.Utilities public static Dictionary RegisteredServices { get; set; } = new Dictionary(); public static bool Inited { get; set; } - public static void Init() + public static void Init(HttpClientHandler httpClientHandler = null) { if(Inited) { @@ -31,7 +32,8 @@ namespace Bit.Core.Utilities var cryptoFunctionService = new PclCryptoFunctionService(cryptoPrimitiveService); var cryptoService = new CryptoService(storageService, secureStorageService, cryptoFunctionService); var tokenService = new TokenService(storageService); - var apiService = new ApiService(tokenService, platformUtilsService, (bool expired) => Task.FromResult(0)); + var apiService = new ApiService(tokenService, platformUtilsService, (bool expired) => Task.FromResult(0), + httpClientHandler); var appIdService = new AppIdService(storageService); var userService = new UserService(storageService, tokenService); var settingsService = new SettingsService(userService, storageService); diff --git a/src/iOS/iOS.csproj b/src/iOS/iOS.csproj index c90a1b54c..06b9cf417 100644 --- a/src/iOS/iOS.csproj +++ b/src/iOS/iOS.csproj @@ -132,6 +132,7 @@ +