Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 27 additions & 11 deletions ESI.NET/EsiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,7 @@ public class EsiClient : IEsiClient
public EsiClient(IOptions<EsiConfig> _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))
Expand Down Expand Up @@ -143,6 +133,32 @@ public void SetCharacterData(AuthorizedCharacterData data)

public void SetIfNoneMatchHeader(string eTag)
=> EsiRequest.ETag = eTag;

/// <summary>
/// Creates the <see cref="HttpClientHandler"/> used when no <see cref="HttpClient"/> is supplied.
/// </summary>
/// <remarks>
/// Automatic decompression is only configured when the handler reports support for it.
/// On Blazor WebAssembly the underlying browser handler throws
/// <see cref="PlatformNotSupportedException"/> from the setter, because the browser's fetch
/// API performs content decoding itself. See https://github.com/seraphx2/ESI.NET/issues/77.
/// </remarks>
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
Expand Down