Only set AutomaticDecompression when the platform supports it - #79
Open
thelocalsim wants to merge 1 commit into
Open
Only set AutomaticDecompression when the platform supports it#79thelocalsim wants to merge 1 commit into
thelocalsim wants to merge 1 commit into
Conversation
Constructing an EsiClient on Blazor WebAssembly threw
"One or more errors occurred. (Operation is not supported on this platform.)"
before any request was made.
The default handler set HttpClientHandler.AutomaticDecompression
unconditionally. On the browser runtime that property is annotated
[UnsupportedOSPlatform("browser")] and the underlying BrowserHttpHandler
throws PlatformNotSupportedException from both the getter and the setter,
because the fetch API performs content decoding itself and exposes no way
to configure it.
Guard the assignment with HttpClientHandler.SupportsAutomaticDecompression,
which the browser handler defines as a compile-time constant false and which
returns true on every other supported platform. The property is a plain
bool getter that never throws, and it is present in every target framework
this project builds for (netstandard2.0, net462 through net48, netcoreapp3.1,
net6.0 and net7.0), so no additional conditional compilation is needed.
Behaviour is unchanged everywhere decompression is supported: the existing
#if NET split between DecompressionMethods.All and GZip|Deflate is preserved.
On Blazor WebAssembly the client now constructs successfully and the browser
handles gzip/deflate/brotli transparently.
The handler construction moves into a small private factory so that a
handler is still only allocated when no HttpClient is supplied by the caller.
Fixes seraphx2#77
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #77.
The problem
Constructing an
EsiClientunder Blazor WebAssembly fails immediately, before any request is made:EsiClient's default handler setAutomaticDecompressionunconditionally:@AdmirableTable identified this line in the issue thread and confirmed empirically that removing the assignment clears the error. The runtime side matches: in
dotnet/runtime,HttpClientHandler.AutomaticDecompressioncarries[UnsupportedOSPlatform("browser")]and delegates to the underlying handler, and the browser implementation throws from both accessors:The browser's fetch API performs content decoding itself and exposes no way to configure it, which is why the property is unsupported rather than merely ignored.
The fix
Guard the assignment with
HttpClientHandler.SupportsAutomaticDecompression. The same browser handler declares it as a compile-time constant:It is a plain
boolgetter that never throws, so it is safe to call on every platform, and it is present in all nine target frameworks this project builds for —netstandard2.0,net462/net47/net471/net472/net48,netcoreapp3.1,net6.0,net7.0— so the guard itself needs no conditional compilation.Handler construction moves into a small private factory, so a handler is still only allocated when the caller does not supply their own
HttpClient.Behaviour
#if NETsplit betweenDecompressionMethods.AllandGZip | Deflateis preserved verbatim, including the linkedsso-issues#81comment explaining the brotli change.A note on verification
I do not have a Blazor WebAssembly environment to hand, so I have not run the fix end to end — the diagnosis rests on the reporter's confirmation plus the runtime source above, and the fix follows the capability-probe pattern those
Supports*properties exist for. The repository has no test project and I had no .NET SDK available locally to compile-check the multi-target build, so please let CI confirm the build across all nine TFMs. Happy to adjust if anything falls out.I deliberately kept this minimal and did not take the RestSharp replacement suggested in the issue thread — that is a much larger dependency and API change, and this bug does not require it.
🤖 Generated with Claude Code