diff --git a/ESI.NET/EsiClient.cs b/ESI.NET/EsiClient.cs index 5b00fe4..aa7f45a 100644 --- a/ESI.NET/EsiClient.cs +++ b/ESI.NET/EsiClient.cs @@ -21,17 +21,7 @@ public class EsiClient : IEsiClient public EsiClient(IOptions _config, HttpClient _client = null) { config = _config.Value; - client = _client ?? new HttpClient(new HttpClientHandler - { - - -// Switch to All which adds brotli encoding for .net core due to https://github.com/ccpgames/sso-issues/issues/81 -#if NET - AutomaticDecompression = DecompressionMethods.All -#else - AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate -#endif - }); + client = _client ?? new HttpClient(CreateDefaultHandler()); // Enforce user agent value if (string.IsNullOrEmpty(config.UserAgent)) @@ -143,6 +133,32 @@ public void SetCharacterData(AuthorizedCharacterData data) public void SetIfNoneMatchHeader(string eTag) => EsiRequest.ETag = eTag; + + /// + /// Creates the used when no is supplied. + /// + /// + /// Automatic decompression is only configured when the handler reports support for it. + /// On Blazor WebAssembly the underlying browser handler throws + /// from the setter, because the browser's fetch + /// API performs content decoding itself. See https://github.com/seraphx2/ESI.NET/issues/77. + /// + private static HttpClientHandler CreateDefaultHandler() + { + var handler = new HttpClientHandler(); + + if (handler.SupportsAutomaticDecompression) + { + // Switch to All which adds brotli encoding for .net core due to https://github.com/ccpgames/sso-issues/issues/81 +#if NET + handler.AutomaticDecompression = DecompressionMethods.All; +#else + handler.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate; +#endif + } + + return handler; + } } public interface IEsiClient