We have .NET Framework 4.5, .NET Core 2.1, and .NET Standard 2.0 client libraries on Windows and Linux that all use HttpClient. Looking for guidance on enabling HTTP2 whenever possible, with fallback to HTTP1.1.
For background, our servers already support HTTP2 (and some even HTTP3/Quic) and everything is over TLS 1.2.
Looking beyond, what's the plan for HTTP3/Quic on the client side? With some work from Cloudflare, we've enabled HTTP3 on some servers and the performance is again notable, so we're trying to establish the plan here.
I do see the announcement here. Seems like a reasonable approach and explains .NET Core 3. So we can scope this to just guidance on HTTP2 on .NET Framework, .NET standard and then the plan for HTTP3.
HTTP/2 is not supported on .NET Framework. The HTTP stack on .NET Framework doesn't have that support and there are no plans to add it.
However, you can use the System.Net.Http.WinHttpHandler NuGet package with .NET Framework. That handler for HttpClient does support HTTP/2. You will have to explicitly use that handler in your code like this for .NET Framework:
c#
var handler = new WinHttpHandler();
var client = new HttpClient(handler);
We don't have a mechanism to check the maximum HTTP version supported by the library.
Some (unconfirmed) thoughts on how you might do this: you can do some feature detection to see if you're running in .NET Core 3.0, or maybe set HttpRequestMessage.Version to HTTP/2 and then check the HttpResponseMessage.Version to see what the server responded with.
Thanks @davidsh What about HTTP2 for libraries targeting the .NET Standard spec? From here .NET Core 3.0 should have access to all APIs in .NET Standard 2.1 but it doesn't imply that .NET Standard will support all .NET Core 3.0 APIs.
Did a quick test with <TargetFrameworks>netstandard2.1;netcoreapp3.0</TargetFrameworks> and then var client = new HttpClient() { DefaultRequestVersion = new Version(2, 0) };. It compiles for netcore3.0 but DefaultRequestVersion isn't available under netstandard2.1.
If I fill out the current support and plan for HTTP2 and 3, here is what I've gathered so far. Please help me capture the ?'s
Plan ?
Thanks
Did a quick test with
<TargetFrameworks>netstandard2.1;netcoreapp3.0</TargetFrameworks>and thenvar client = new HttpClient() { DefaultRequestVersion = new Version(2, 0) };. It compiles fornetcore3.0butDefaultRequestVersionisn't available undernetstandard2.1.
You'll have to use HttpRequestMessage.Version.
.NET Standard 2.x: ?
.NET Standard 1.1 has the APIs necessary to use basic HTTP/2.
.NET Standard 2.1 has the HttpResponseMessage.TrailingHeaders API which some services (like gRPC) use.
Actually supporting HTTP/2 depends on which libraries you're running against -- .NET Standard is just a set of APIs, not implementation.
HTTP3
Only prototyping at this point. Nothing to announce.
Only prototyping at this point. Nothing to announce.
Regarding HTTP/3 work, we are beginning early work mostly on the transport layer (QUIC). See: dotnet/corefx#42311
We have not announced any commitment regarding HTTP/3 functionality for .NET 5 RTM. But you can follow this repo to watch early progress in HTTP/3.
@scalablecory @davidsh I understand netstandard2.1 is an API spec. As library builders, we prefer targeting and supporting that instead of a bunch of various run-times.
So how does a library targeting netstandard2.1 go about using HTTP2?
Most helpful comment
@scalablecory @davidsh I understand
netstandard2.1is an API spec. As library builders, we prefer targeting and supporting that instead of a bunch of various run-times.So how does a library targeting
netstandard2.1go about using HTTP2?